Skip to content

Commit 499a431

Browse files
authored
Prepare release for launcher v1.3 (#60)
* update deps to latest * add metrics support * add a counter to the example * update readme with metrics options * update changelog for v1.3 release * lockdown types
1 parent bcda224 commit 499a431

File tree

8 files changed

+143
-37
lines changed

8 files changed

+143
-37
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
44

55
## Unreleased
66

7+
## 1.3.0
8+
* OpenTelemetry dependencies have been upgraded to API v1.3.0, core v1.8.0,
9+
with auto-instrumentations-node v0.35.0.
10+
* Support for the recently GA'd metrics SDK has been added. This functionality
11+
is opt-in and users will need to set `metricsEnabeld: true` in code, or via
12+
the environment by setting `LS_METRICS_ENABLED=true`. Refer to the README
13+
for all metrics related configuration options.
14+
715
## 1.2.0
816
* This release changes the default export format for launcher from OTLP/JSON to
917
OTLP/proto (e.g. proto over HTTP). Aside from the change in export format, this

README.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,18 @@ OpenTelemetry API and some examples of its usage:
4545

4646
### Configuration Options
4747

48-
| Config Option | Env Variable | Required | Default |
49-
| -------------- | -------------------------------- | -------- | --------------------------------------------- |
50-
| serviceName | LS_SERVICE_NAME | y | - |
51-
| serviceVersion | LS_SERVICE_VERSION | n | unknown |
52-
| spanEndpoint | OTEL_EXPORTER_OTLP_SPAN_ENDPOINT | n | https://ingest.lightstep.com/traces/otlp/v0.9 |
53-
| accessToken | LS_ACCESS_TOKEN | n | - |
54-
| logLevel | OTEL_LOG_LEVEL | n | info |
55-
| propagators | OTEL_PROPAGATORS | n | b3 |
56-
| resource | OTEL_RESOURCE_ATTRIBUTES | n | - |
48+
| Config Option | Env Variable | Required | Default |
49+
| ---------------------- | ----------------------------------- | -------- | ---------------------------------------------- |
50+
| serviceName | LS_SERVICE_NAME | y | - |
51+
| serviceVersion | LS_SERVICE_VERSION | n | unknown |
52+
| spanEndpoint | OTEL_EXPORTER_OTLP_TRACES_ENDPOINT | n | https://ingest.lightstep.com/traces/otlp/v0.9 |
53+
| metricsEndpoint | OTEL_EXPORTER_OTLP_METRICS_ENDPOINT | n | https://ingest.lightstep.com/metrics/otlp/v0.9 |
54+
| metricsReportingPeriod | OTEL_EXPORTER_OTLP_METRICS_PERIOD | n | 30000 |
55+
| metricsEnabled | LS_METRICS_ENABLED | n | false |
56+
| accessToken | LS_ACCESS_TOKEN | n | - |
57+
| logLevel | OTEL_LOG_LEVEL | n | info |
58+
| propagators | OTEL_PROPAGATORS | n | b3 |
59+
| resource | OTEL_RESOURCE_ATTRIBUTES | n | - |
5760

5861
#### Additional Options
5962

example/index.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,24 @@ const accessToken = 'YOUR ACCESS TOKEN';
77

88
const sdk = lightstep.configureOpenTelemetry({
99
accessToken,
10-
serviceName: 'locl-ex',
11-
metricInterval: 3000,
10+
serviceName: 'launcher-node-ex',
11+
metricsEnabled: true, // default is false
12+
metricsReportingPeriod: 10000, // default is 30000
1213
logLevel: DiagLogLevel.ALL,
1314
});
1415

16+
const appName = 'launcher-node-example';
17+
1518
sdk.start().then(() => {
16-
const tracer = opentelemetry.trace.getTracer('locl-node-example');
19+
const tracer = opentelemetry.trace.getTracer(appName);
20+
const meter = opentelemetry.metrics.getMeter(appName);
21+
const counter = meter.createCounter('test-counter');
1722
let count = 0;
1823
setInterval(() => {
1924
count++;
2025
const span = tracer.startSpan('test-span');
2126
span.setAttribute('count', count);
2227
span.end();
23-
24-
// force to export traces
25-
// tracer.getActiveSpanProcessor().forceFlush();
28+
counter.add(1);
2629
}, 10000);
2730
}, console.log);

package.json

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,20 @@
4646
"access": "public"
4747
},
4848
"dependencies": {
49-
"@opentelemetry/api": "^1.2.0",
50-
"@opentelemetry/api-metrics": "^0.33.0",
51-
"@opentelemetry/auto-instrumentations-node": "~0.33.1",
52-
"@opentelemetry/core": "~1.7.0",
53-
"@opentelemetry/exporter-trace-otlp-proto": "~0.33.0",
54-
"@opentelemetry/propagator-b3": "~1.7.0",
55-
"@opentelemetry/resource-detector-aws": "~1.1.2",
56-
"@opentelemetry/resource-detector-gcp": "~0.27.2",
57-
"@opentelemetry/resources": "~1.7.0",
58-
"@opentelemetry/sdk-metrics": "~0.33.0",
59-
"@opentelemetry/sdk-node": "^0.33.0",
60-
"@opentelemetry/sdk-trace-base": "~1.7.0",
61-
"@opentelemetry/sdk-trace-node": "~1.7.0",
62-
"@opentelemetry/semantic-conventions": "~1.7.0"
49+
"@opentelemetry/api": "^1.3.0",
50+
"@opentelemetry/auto-instrumentations-node": "~0.35.0",
51+
"@opentelemetry/core": "~1.8.0",
52+
"@opentelemetry/exporter-metrics-otlp-proto": "~0.34.0",
53+
"@opentelemetry/exporter-trace-otlp-proto": "~0.34.0",
54+
"@opentelemetry/propagator-b3": "~1.8.0",
55+
"@opentelemetry/resource-detector-aws": "~1.2.1",
56+
"@opentelemetry/resource-detector-gcp": "~0.27.4",
57+
"@opentelemetry/resources": "~1.8.0",
58+
"@opentelemetry/sdk-metrics": "~1.8.0",
59+
"@opentelemetry/sdk-node": "^0.34.0",
60+
"@opentelemetry/sdk-trace-base": "~1.8.0",
61+
"@opentelemetry/sdk-trace-node": "~1.8.0",
62+
"@opentelemetry/semantic-conventions": "~1.8.0"
6363
},
6464
"devDependencies": {
6565
"@types/mocha": "9.1.1",
@@ -79,6 +79,6 @@
7979
"package-json": "^7.0.0",
8080
"sinon": "^14.0.0",
8181
"ts-mocha": "10.0.0",
82-
"typescript": "^4.4.4"
82+
"typescript": "4.4.4"
8383
}
84-
}
84+
}

src/lightstep-opentelemetry-launcher-node.ts

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { B3InjectEncoding, B3Propagator } from '@opentelemetry/propagator-b3';
1414
import { NodeSDK } from '@opentelemetry/sdk-node';
1515
import * as types from './types';
1616
import { VERSION } from './version';
17+
import { PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics';
18+
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-proto';
1719
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto';
1820
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
1921
import { Resource, ResourceAttributes } from '@opentelemetry/resources';
@@ -45,6 +47,9 @@ const PROPAGATOR_LOOKUP_MAP: {
4547
/** Default values for LightstepNodeSDKConfiguration */
4648
const 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
*/
266280
function 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,

src/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ export interface LightstepConfigType {
99
serviceName?: string;
1010
serviceVersion?: string;
1111
spanEndpoint?: string;
12+
metricsEndpoint?: string;
13+
metricsReportingPeriod?: number;
14+
metricsEnabled?: boolean;
1215
propagators?: string;
1316
logger?: DiagLogger;
1417
logLevel?: DiagLogLevel;
@@ -21,6 +24,10 @@ export interface LightstepEnvType {
2124
LS_SERVICE_NAME?: string;
2225
LS_SERVICE_VERSION?: string;
2326
OTEL_EXPORTER_OTLP_SPAN_ENDPOINT?: string;
27+
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT?: string;
28+
OTEL_EXPORTER_OTLP_METRICS_ENDPOINT?: string;
29+
OTEL_EXPORTER_OTLP_METRICS_PERIOD?: string;
30+
LS_METRICS_ENABLED?: string;
2431
OTEL_PROPAGATORS?: string;
2532
}
2633

src/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
// this is autogenerated file, see scripts/version-update.js
2-
export const VERSION = '1.2.0';
2+
export const VERSION = '1.3.0';

test/lightstep-opentelemetry-launcher-node.test.ts

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { context, DiagLogLevel, propagation, trace } from '@opentelemetry/api';
1+
import {
2+
context,
3+
DiagLogLevel,
4+
propagation,
5+
trace,
6+
metrics,
7+
createNoopMeter,
8+
} from '@opentelemetry/api';
29
import {
310
CompositePropagator,
411
W3CTraceContextPropagator,
@@ -343,5 +350,42 @@ describe('Lightstep OpenTelemetry Launcher Node', () => {
343350
);
344351
});
345352
});
353+
354+
describe('metrics', () => {
355+
const noopMeter = createNoopMeter();
356+
357+
it('is disabled by default', async () => {
358+
const sdk = lightstep.configureOpenTelemetry(minimalConfig);
359+
assert.ok(sdk instanceof NodeSDK);
360+
361+
await sdk.start();
362+
363+
assert.strictEqual(metrics.getMeter('test'), noopMeter);
364+
});
365+
366+
it('can be enabled by code', async () => {
367+
const sdk = lightstep.configureOpenTelemetry({
368+
...minimalConfig,
369+
metricsEnabled: true,
370+
});
371+
assert.ok(sdk instanceof NodeSDK);
372+
373+
await sdk.start();
374+
375+
// a non-noop meter indicates the metrics sdk was configured
376+
assert.notStrictEqual(metrics.getMeter('test'), noopMeter);
377+
});
378+
379+
it('can be enabled by environment variable', async () => {
380+
process.env.LS_METRICS_ENABLED = 'true';
381+
const sdk = lightstep.configureOpenTelemetry(minimalConfig);
382+
assert.ok(sdk instanceof NodeSDK);
383+
384+
await sdk.start();
385+
386+
// a non-noop meter indicates the metrics sdk was configured
387+
assert.notStrictEqual(metrics.getMeter('test'), noopMeter);
388+
});
389+
});
346390
});
347391
});

0 commit comments

Comments
 (0)