Skip to content

Commit 3f82ff4

Browse files
weyerttapico-weyertvmarchaud
authored
feat: apply spec changes for TraceParams (#2190)
Co-authored-by: Weyert de Boer <[email protected]> Co-authored-by: Valentin Marchaud <[email protected]>
1 parent 6885278 commit 3f82ff4

File tree

10 files changed

+76
-75
lines changed

10 files changed

+76
-75
lines changed

packages/opentelemetry-sdk-node/README.md

+15-14
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![NPM Published Version][npm-img]][npm-url]
44
[![dependencies][dependencies-image]][dependencies-url]
5-
[![devDependencies][devDependencies-image]][devDependencies-url]
5+
[![devDependencies][devdependencies-image]][devdependencies-url]
66
[![Apache License][license-image]][license-image]
77

88
This package provides the full OpenTelemetry SDK for Node.js including tracing and metrics.
@@ -34,13 +34,16 @@ $ npm install @opentelemetry/auto-instrumentations-node
3434

3535
Before any other module in your application is loaded, you must initialize the SDK.
3636
If you fail to initialize the SDK or initialize it too late, no-op implementations will be provided to any library which acquires a tracer or meter from the API.
37+
3738
This example uses Jaeger and Prometheus, but exporters exist for [other tracing backends][other-tracing-backends].
3839

3940
```javascript
4041
const opentelemetry = require("@opentelemetry/sdk-node");
4142
const { JaegerExporter } = require("@opentelemetry/exporter-jaeger");
4243
const { PrometheusExporter } = require("@opentelemetry/exporter-prometheus");
43-
const { getNodeAutoInstrumentations } = require("@opentelemetry/auto-instrumentations-node");
44+
const {
45+
getNodeAutoInstrumentations,
46+
} = require("@opentelemetry/auto-instrumentations-node");
4447

4548
const jaegerExporter = new JaegerExporter({
4649
serviceName: 'my-service',
@@ -59,22 +62,21 @@ const sdk = new opentelemetry.NodeSDK({
5962

6063
// You can optionally detect resources asynchronously from the environment.
6164
// Detected resources are merged with the resources provided in the SDK configuration.
62-
sdk
63-
.start()
64-
.then(() => {
65-
// Resources have been detected and SDK is started
66-
})
65+
sdk.start().then(() => {
66+
// Resources have been detected and SDK is started
67+
});
6768

6869
// You can also use the shutdown method to gracefully shut down the SDK before process shutdown
6970
// or on some operating system signal.
7071
const process = require("process");
7172
process.on("SIGTERM", () => {
72-
sdk.shutdown()
73+
sdk
74+
.shutdown()
7375
.then(
7476
() => console.log("SDK shut down successfully"),
75-
(err) => console.log("Error shutting down SDK", err),
77+
(err) => console.log("Error shutting down SDK", err)
7678
)
77-
.finally(() => process.exit(0))
79+
.finally(() => process.exit(0));
7880
});
7981
```
8082

@@ -126,7 +128,7 @@ Configure a custom sampler. By default all traces will be sampled.
126128

127129
Configure a trace exporter. If an exporter OR span processor is not configured, the tracing SDK will not be initialized and registered. If an exporter is configured, it will be used with a [BatchSpanProcessor](../opentelemetry-tracing/src/export/BatchSpanProcessor.ts).
128130

129-
### traceParams
131+
### spanLimits
130132

131133
Configure tracing parameters. These are the same trace parameters used to [configure a tracer](../opentelemetry-tracing/src/types.ts#L71).
132134

@@ -145,9 +147,8 @@ Apache 2.0 - See [LICENSE][license-url] for more information.
145147
[license-image]: https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat
146148
[dependencies-image]: https://status.david-dm.org/gh/open-telemetry/opentelemetry-js.svg?path=packages%2Fopentelemetry-sdk-node
147149
[dependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js?path=packages%2Fopentelemetry-sdk-node
148-
[devDependencies-image]: https://status.david-dm.org/gh/open-telemetry/opentelemetry-js.svg?path=packages%2Fopentelemetry-sdk-node&type=dev
149-
[devDependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js?path=packages%2Fopentelemetry-sdk-node&type=dev
150+
[devdependencies-image]: https://status.david-dm.org/gh/open-telemetry/opentelemetry-js.svg?path=packages%2Fopentelemetry-sdk-node&type=dev
151+
[devdependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js?path=packages%2Fopentelemetry-sdk-node&type=dev
150152
[npm-url]: https://www.npmjs.com/package/@opentelemetry/sdk-node
151153
[npm-img]: https://badge.fury.io/js/%40opentelemetry%2Fsdk-node.svg
152-
153154
[other-tracing-backends]: https://github.com/open-telemetry/opentelemetry-js#trace-exporters

packages/opentelemetry-sdk-node/src/sdk.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ export class NodeSDK {
6767
if (configuration.sampler) {
6868
tracerProviderConfig.sampler = configuration.sampler;
6969
}
70-
if (configuration.traceParams) {
71-
tracerProviderConfig.traceParams = configuration.traceParams;
70+
if (configuration.spanLimits) {
71+
tracerProviderConfig.spanLimits = configuration.spanLimits;
7272
}
7373

7474
const spanProcessor =

packages/opentelemetry-sdk-node/src/types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { Resource } from '@opentelemetry/resources';
2222
import {
2323
SpanExporter,
2424
SpanProcessor,
25-
TraceParams,
25+
SpanLimits,
2626
} from '@opentelemetry/tracing';
2727

2828
export interface NodeSDKConfiguration {
@@ -38,5 +38,5 @@ export interface NodeSDKConfiguration {
3838
sampler: Sampler;
3939
spanProcessor: SpanProcessor;
4040
traceExporter: SpanExporter;
41-
traceParams: TraceParams;
41+
spanLimits: SpanLimits;
4242
}

packages/opentelemetry-tracing/src/Span.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { ReadableSpan } from './export/ReadableSpan';
2929
import { TimedEvent } from './TimedEvent';
3030
import { Tracer } from './Tracer';
3131
import { SpanProcessor } from './SpanProcessor';
32-
import { TraceParams } from './types';
32+
import { SpanLimits } from './types';
3333
import { SpanAttributeValue, Context } from '@opentelemetry/api';
3434
import { ExceptionEventName } from './enums';
3535

@@ -56,7 +56,7 @@ export class Span implements api.Span, ReadableSpan {
5656
private _ended = false;
5757
private _duration: api.HrTime = [-1, -1];
5858
private readonly _spanProcessor: SpanProcessor;
59-
private readonly _traceParams: TraceParams;
59+
private readonly _spanLimits: SpanLimits;
6060

6161
/** Constructs a new Span instance. */
6262
constructor(
@@ -77,7 +77,7 @@ export class Span implements api.Span, ReadableSpan {
7777
this.startTime = timeInputToHrTime(startTime);
7878
this.resource = parentTracer.resource;
7979
this.instrumentationLibrary = parentTracer.instrumentationLibrary;
80-
this._traceParams = parentTracer.getActiveTraceParams();
80+
this._spanLimits = parentTracer.getSpanLimits();
8181
this._spanProcessor = parentTracer.getActiveSpanProcessor();
8282
this._spanProcessor.onStart(this, context);
8383
}
@@ -100,7 +100,7 @@ export class Span implements api.Span, ReadableSpan {
100100

101101
if (
102102
Object.keys(this.attributes).length >=
103-
this._traceParams.numberOfAttributesPerSpan! &&
103+
this._spanLimits.attributeCountLimit! &&
104104
!Object.prototype.hasOwnProperty.call(this.attributes, key)
105105
) {
106106
return this;
@@ -129,7 +129,7 @@ export class Span implements api.Span, ReadableSpan {
129129
startTime?: api.TimeInput
130130
): this {
131131
if (this._isSpanEnded()) return this;
132-
if (this.events.length >= this._traceParams.numberOfEventsPerSpan!) {
132+
if (this.events.length >= this._spanLimits.eventCountLimit!) {
133133
api.diag.warn('Dropping extra events.');
134134
this.events.shift();
135135
}

packages/opentelemetry-tracing/src/Tracer.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ import {
2424
import { Resource } from '@opentelemetry/resources';
2525
import { BasicTracerProvider } from './BasicTracerProvider';
2626
import { Span } from './Span';
27-
import { TraceParams, TracerConfig } from './types';
27+
import { SpanLimits, TracerConfig } from './types';
2828
import { mergeConfig } from './utility';
2929

3030
/**
3131
* This class represents a basic tracer.
3232
*/
3333
export class Tracer implements api.Tracer {
3434
private readonly _sampler: api.Sampler;
35-
private readonly _traceParams: TraceParams;
35+
private readonly _spanLimits: SpanLimits;
3636
private readonly _idGenerator: IdGenerator;
3737
readonly resource: Resource;
3838
readonly instrumentationLibrary: InstrumentationLibrary;
@@ -47,7 +47,7 @@ export class Tracer implements api.Tracer {
4747
) {
4848
const localConfig = mergeConfig(config);
4949
this._sampler = localConfig.sampler;
50-
this._traceParams = localConfig.traceParams;
50+
this._spanLimits = localConfig.spanLimits;
5151
this._idGenerator = config.idGenerator || new RandomIdGenerator();
5252
this.resource = _tracerProvider.resource;
5353
this.instrumentationLibrary = instrumentationLibrary;
@@ -124,9 +124,9 @@ export class Tracer implements api.Tracer {
124124
return span;
125125
}
126126

127-
/** Returns the active {@link TraceParams}. */
128-
getActiveTraceParams(): TraceParams {
129-
return this._traceParams;
127+
/** Returns the active {@link SpanLimits}. */
128+
getSpanLimits(): SpanLimits {
129+
return this._spanLimits;
130130
}
131131

132132
getActiveSpanProcessor() {

packages/opentelemetry-tracing/src/config.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ const FALLBACK_OTEL_TRACES_SAMPLER = TracesSamplerValues.AlwaysOn;
3131
/**
3232
* Default configuration. For fields with primitive values, any user-provided
3333
* value will override the corresponding default value. For fields with
34-
* non-primitive values (like `traceParams`), the user-provided value will be
34+
* non-primitive values (like `spanLimits`), the user-provided value will be
3535
* used to extend the default value.
3636
*/
3737
export const DEFAULT_CONFIG = {
3838
sampler: buildSamplerFromEnv(env),
3939
forceFlushTimeoutMillis: 30000,
40-
traceParams: {
41-
numberOfAttributesPerSpan: getEnv().OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT,
42-
numberOfLinksPerSpan: getEnv().OTEL_SPAN_LINK_COUNT_LIMIT,
43-
numberOfEventsPerSpan: getEnv().OTEL_SPAN_EVENT_COUNT_LIMIT,
40+
spanLimits: {
41+
attributeCountLimit: getEnv().OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT,
42+
linkCountLimit: getEnv().OTEL_SPAN_LINK_COUNT_LIMIT,
43+
eventCountLimit: getEnv().OTEL_SPAN_EVENT_COUNT_LIMIT,
4444
},
4545
};
4646

packages/opentelemetry-tracing/src/types.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ export interface TracerConfig {
2929
*/
3030
sampler?: Sampler;
3131

32-
/** Trace Parameters */
33-
traceParams?: TraceParams;
32+
/** Span Limits */
33+
spanLimits?: SpanLimits;
3434

3535
/** Resource associated with trace telemetry */
3636
resource?: Resource;
@@ -62,13 +62,13 @@ export interface SDKRegistrationConfig {
6262
}
6363

6464
/** Global configuration of trace service */
65-
export interface TraceParams {
66-
/** numberOfAttributesPerSpan is number of attributes per span */
67-
numberOfAttributesPerSpan?: number;
68-
/** numberOfLinksPerSpan is number of links per span */
69-
numberOfLinksPerSpan?: number;
70-
/** numberOfEventsPerSpan is number of message events per span */
71-
numberOfEventsPerSpan?: number;
65+
export interface SpanLimits {
66+
/** attributeCountLimit is number of attributes per span */
67+
attributeCountLimit?: number;
68+
/** linkCountLimit is number of links per span */
69+
linkCountLimit?: number;
70+
/** eventCountLimit is number of message events per span */
71+
eventCountLimit?: number;
7272
}
7373

7474
/** Interface configuration for a buffer. */

packages/opentelemetry-tracing/src/utility.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ export function mergeConfig(userConfig: TracerConfig) {
3333
userConfig
3434
);
3535

36-
target.traceParams = Object.assign(
36+
target.spanLimits = Object.assign(
3737
{},
38-
DEFAULT_CONFIG.traceParams,
39-
userConfig.traceParams || {}
38+
DEFAULT_CONFIG.spanLimits,
39+
userConfig.spanLimits || {}
4040
);
4141

4242
return target;

packages/opentelemetry-tracing/test/BasicTracerProvider.test.ts

+26-26
Original file line numberDiff line numberDiff line change
@@ -78,51 +78,51 @@ describe('BasicTracerProvider', () => {
7878
assert.ok(provider instanceof BasicTracerProvider);
7979
});
8080

81-
it('should construct an instance with default trace params', () => {
81+
it('should construct an instance with default span limits', () => {
8282
const tracer = new BasicTracerProvider({}).getTracer('default');
83-
assert.deepStrictEqual(tracer.getActiveTraceParams(), {
84-
numberOfAttributesPerSpan: 128,
85-
numberOfEventsPerSpan: 128,
86-
numberOfLinksPerSpan: 128,
83+
assert.deepStrictEqual(tracer.getSpanLimits(), {
84+
attributeCountLimit: 128,
85+
eventCountLimit: 128,
86+
linkCountLimit: 128,
8787
});
8888
});
8989

90-
it('should construct an instance with customized numberOfAttributesPerSpan trace params', () => {
90+
it('should construct an instance with customized attributeCountLimit span limits', () => {
9191
const tracer = new BasicTracerProvider({
92-
traceParams: {
93-
numberOfAttributesPerSpan: 100,
92+
spanLimits: {
93+
attributeCountLimit: 100,
9494
},
9595
}).getTracer('default');
96-
assert.deepStrictEqual(tracer.getActiveTraceParams(), {
97-
numberOfAttributesPerSpan: 100,
98-
numberOfEventsPerSpan: 128,
99-
numberOfLinksPerSpan: 128,
96+
assert.deepStrictEqual(tracer.getSpanLimits(), {
97+
attributeCountLimit: 100,
98+
eventCountLimit: 128,
99+
linkCountLimit: 128,
100100
});
101101
});
102102

103-
it('should construct an instance with customized numberOfEventsPerSpan trace params', () => {
103+
it('should construct an instance with customized eventCountLimit span limits', () => {
104104
const tracer = new BasicTracerProvider({
105-
traceParams: {
106-
numberOfEventsPerSpan: 300,
105+
spanLimits: {
106+
eventCountLimit: 300,
107107
},
108108
}).getTracer('default');
109-
assert.deepStrictEqual(tracer.getActiveTraceParams(), {
110-
numberOfAttributesPerSpan: 128,
111-
numberOfEventsPerSpan: 300,
112-
numberOfLinksPerSpan: 128,
109+
assert.deepStrictEqual(tracer.getSpanLimits(), {
110+
attributeCountLimit: 128,
111+
eventCountLimit: 300,
112+
linkCountLimit: 128,
113113
});
114114
});
115115

116-
it('should construct an instance with customized numberOfLinksPerSpan trace params', () => {
116+
it('should construct an instance with customized linkCountLimit span limits', () => {
117117
const tracer = new BasicTracerProvider({
118-
traceParams: {
119-
numberOfLinksPerSpan: 10,
118+
spanLimits: {
119+
linkCountLimit: 10,
120120
},
121121
}).getTracer('default');
122-
assert.deepStrictEqual(tracer.getActiveTraceParams(), {
123-
numberOfAttributesPerSpan: 128,
124-
numberOfEventsPerSpan: 128,
125-
numberOfLinksPerSpan: 10,
122+
assert.deepStrictEqual(tracer.getSpanLimits(), {
123+
attributeCountLimit: 128,
124+
eventCountLimit: 128,
125+
linkCountLimit: 10,
126126
});
127127
});
128128

packages/opentelemetry-tracing/test/Span.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ const performanceTimeOrigin = hrTime();
3737

3838
describe('Span', () => {
3939
const tracer = new BasicTracerProvider({
40-
traceParams: {
41-
numberOfAttributesPerSpan: 100,
42-
numberOfEventsPerSpan: 100,
40+
spanLimits: {
41+
attributeCountLimit: 100,
42+
eventCountLimit: 100,
4343
},
4444
}).getTracer('default');
4545
const name = 'span1';

0 commit comments

Comments
 (0)