@@ -14,6 +14,8 @@ import { B3InjectEncoding, B3Propagator } from '@opentelemetry/propagator-b3';
1414import { NodeSDK } from '@opentelemetry/sdk-node' ;
1515import * as types from './types' ;
1616import { VERSION } from './version' ;
17+ import { PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics' ;
18+ import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-proto' ;
1719import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto' ;
1820import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions' ;
1921import { Resource , ResourceAttributes } from '@opentelemetry/resources' ;
@@ -45,6 +47,9 @@ const PROPAGATOR_LOOKUP_MAP: {
4547/** Default values for LightstepNodeSDKConfiguration */
4648const LS_DEFAULTS : Partial < types . LightstepNodeSDKConfiguration > = {
4749 spanEndpoint : 'https://ingest.lightstep.com/traces/otlp/v0.9' ,
50+ metricsEndpoint : 'https://ingest.lightstep.com/metrics/otlp/v0.9' ,
51+ metricsReportingPeriod : 30000 ,
52+ metricsEnabled : false ,
4853 propagators : PROPAGATION_FORMATS . B3 ,
4954} ;
5055
@@ -71,6 +76,7 @@ export function configureOpenTelemetry(
7176 configureBaseResource ( config ) ;
7277 configurePropagation ( config ) ;
7378 configureTraceExporter ( config ) ;
79+ configureMetricExporter ( config ) ;
7480 configureInstrumentations ( config ) ;
7581
7682 return new NodeSDK ( config ) ;
@@ -134,12 +140,9 @@ function logConfig(
134140 lsConfig : Partial < types . LightstepNodeSDKConfiguration > ,
135141 mergedConfig : Partial < types . LightstepNodeSDKConfiguration >
136142) {
137- diag . debug ( 'Default config: ' , defaults ) ;
138143 diag . debug ( 'Default config: ' , defaults ) ;
139144 diag . debug ( 'Config from environment' , envConfig ) ;
140- diag . debug ( 'Default config: ' , defaults ) ;
141145 diag . debug ( 'Config from code: ' , lsConfig ) ;
142- diag . debug ( 'Default config: ' , defaults ) ;
143146 diag . debug ( 'Merged Config' , mergedConfig ) ;
144147}
145148
@@ -153,8 +156,19 @@ function configFromEnvironment(): Partial<types.LightstepNodeSDKConfiguration> {
153156 if ( env . LS_ACCESS_TOKEN ) envConfig . accessToken = env . LS_ACCESS_TOKEN ;
154157 if ( env . LS_SERVICE_NAME ) envConfig . serviceName = env . LS_SERVICE_NAME ;
155158 if ( env . LS_SERVICE_VERSION ) envConfig . serviceVersion = env . LS_SERVICE_VERSION ;
159+ // for backwards compatibility only, this has been renamed to `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT`
156160 if ( env . OTEL_EXPORTER_OTLP_SPAN_ENDPOINT )
157161 envConfig . spanEndpoint = env . OTEL_EXPORTER_OTLP_SPAN_ENDPOINT ;
162+ if ( env . OTEL_EXPORTER_OTLP_TRACES_ENDPOINT )
163+ envConfig . spanEndpoint = env . OTEL_EXPORTER_OTLP_TRACES_ENDPOINT ;
164+ if ( env . OTEL_EXPORTER_OTLP_METRICS_ENDPOINT )
165+ envConfig . metricsEndpoint = env . OTEL_EXPORTER_OTLP_METRICS_ENDPOINT ;
166+ if ( env . OTEL_EXPORTER_OTLP_METRICS_PERIOD )
167+ envConfig . metricsReportingPeriod = parseInt (
168+ env . OTEL_EXPORTER_OTLP_METRICS_PERIOD
169+ ) ;
170+ if ( env . LS_METRICS_ENABLED )
171+ envConfig . metricsEnabled = env . LS_METRICS_ENABLED === 'true' ;
158172 if ( env . OTEL_PROPAGATORS ) envConfig . propagators = env . OTEL_PROPAGATORS ;
159173 return envConfig ;
160174}
@@ -260,7 +274,7 @@ function configureInstrumentations(
260274}
261275
262276/**
263- * Configures export as JSON over HTTP to the configured spanEndpoint
277+ * Configures export as proto over HTTP to the configured spanEndpoint
264278 * @param config
265279 */
266280function configureTraceExporter (
@@ -281,6 +295,33 @@ function configureTraceExporter(
281295 } ) ;
282296}
283297
298+ /**
299+ * Configures export as proto over HTTP to the configured metricsEndpoint
300+ * @param config
301+ */
302+ function configureMetricExporter (
303+ config : Partial < types . LightstepNodeSDKConfiguration >
304+ ) {
305+ if ( ! config . metricsEnabled || config . metricReader ) {
306+ return ;
307+ }
308+
309+ const headers : { [ key : string ] : string } = { } ;
310+ if ( config . accessToken ) {
311+ headers [ ACCESS_TOKEN_HEADER ] = config . accessToken ;
312+ }
313+
314+ const metricExporter = new OTLPMetricExporter ( {
315+ url : config . metricsEndpoint ,
316+ headers,
317+ } ) ;
318+
319+ config . metricReader = new PeriodicExportingMetricReader ( {
320+ exporter : metricExporter ,
321+ exportIntervalMillis : config . metricsReportingPeriod ,
322+ } ) ;
323+ }
324+
284325/**
285326 * Instantiates a propagator based on a string name where the name appears in
286327 * as a key in the PROPAGATOR_LOOKUP_MAP. Current supported names are: b3,
0 commit comments