Skip to content

Commit 48ecf22

Browse files
mohitk05dyladanFlarna
authored
feat(sdk-trace-base): add dropped attributes and events count on span (#3576)
* feat(sdk-trace-base): add dropped attributes and events count on span * feat(sdk-trace-base): sync with main * feat(sdk-trace-base): [revert] sync with main * feat(sdk-trace-base): fix tests, make both counts truthy * feat(sdk-trace-base): Update dropped counts type to number * feat(sdk-trace-base): Use exposed counts on ReadableSpan in jaeger and zipkin exporters * feat(sdk-trace-base): WIP - revert tsconfig, add new attribute limits * feat(sdk-trace-base): Update attribute truncate method * Fix bad conflict resolution * Remove unused import * chore: lint * feat(sdk-trace-base): Remove dropped event attributes logic, add Jaeger field * feat(sdk-trace-base): Undo formatting in changelog * fix(changelog): Update experimental changelog * Update packages/opentelemetry-sdk-trace-base/src/Span.ts Co-authored-by: Gerhard Stöbich <[email protected]> * Update packages/opentelemetry-sdk-trace-base/src/Span.ts Co-authored-by: Gerhard Stöbich <[email protected]> * fix(sdk-trace-base): Resolve review comments * fix(sdk-trace-base): Fix failing tests * fix(sdk-trace-base): make droppedAttributesCount on event optional * fix(changelog): Update changelog files --------- Co-authored-by: Daniel Dyla <[email protected]> Co-authored-by: Gerhard Stöbich <[email protected]>
1 parent 95bf6fc commit 48ecf22

File tree

25 files changed

+295
-62
lines changed

25 files changed

+295
-62
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/
2020
* feat: support TraceState in SamplingResult [#3530](https://github.com/open-telemetry/opentelemetry-js/pull/3530) @raphael-theriault-swi
2121
* feat(sdk-trace-base): add diagnostic logging when spans are dropped [#3610](https://github.com/open-telemetry/opentelemetry-js/pull/3610) @neoeinstein
2222
* feat: add unit to view instrument selection criteria [#3647](https://github.com/open-telemetry/opentelemetry-js/pull/3647) @jlabatut
23+
* feat(tracing): expose dropped counts for attributes, events and links on span [#3576](https://github.com/open-telemetry/opentelemetry-js/pull/3576) @mohitk05
2324

2425
### :bug: (Bug Fix)
2526

api/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ All notable changes to this project will be documented in this file.
1515
### :rocket: (Enhancement)
1616

1717
* feat(api): add `getActiveBaggage` API [#3385](https://github.com/open-telemetry/opentelemetry-js/pull/3385)
18+
* feat(api): add optional `droppedAttributesCount` property in the `Link` interface [#3576](https://github.com/open-telemetry/opentelemetry-js/pull/3576) @mohitk05
1819

1920
### :bug: (Bug Fix)
2021

api/src/trace/link.ts

+2
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,6 @@ export interface Link {
3737
context: SpanContext;
3838
/** A set of {@link SpanAttributes} on the link. */
3939
attributes?: SpanAttributes;
40+
/** Count of attributes of the link that were dropped due to collection limits */
41+
droppedAttributesCount?: number;
4042
}

experimental/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ All notable changes to experimental packages in this project will be documented
1616
* feat(sdk-node): install diag logger with OTEL_LOG_LEVEL [#3627](https://github.com/open-telemetry/opentelemetry-js/pull/3627) @legendecas
1717
* feat(otlp-exporter-base): add retries [#3207](https://github.com/open-telemetry/opentelemetry-js/pull/3207) @svetlanabrennan
1818
* feat(sdk-node): override IdGenerator when using NodeSDK [#3645](https://github.com/open-telemetry/opentelemetry-js/pull/3645) @haddasbronfman
19+
* feat(otlp-transformer): expose dropped attributes, events and links counts on the transformed otlp span [#3576](https://github.com/open-telemetry/opentelemetry-js/pull/3576) @mohitk05
1920

2021
### :bug: (Bug Fix)
2122

experimental/packages/exporter-trace-otlp-grpc/test/traceHelper.ts

+19-4
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,34 @@ export const mockedReadableSpan: ReadableSpan = {
6161
},
6262
],
6363
events: [
64-
{ name: 'fetchStart', time: [1574120165, 429803070] },
64+
{
65+
name: 'fetchStart',
66+
time: [1574120165, 429803070],
67+
},
6568
{
6669
name: 'domainLookupStart',
6770
time: [1574120165, 429803070],
6871
},
69-
{ name: 'domainLookupEnd', time: [1574120165, 429803070] },
72+
{
73+
name: 'domainLookupEnd',
74+
time: [1574120165, 429803070],
75+
},
7076
{
7177
name: 'connectStart',
7278
time: [1574120165, 429803070],
7379
},
74-
{ name: 'connectEnd', time: [1574120165, 429803070] },
80+
{
81+
name: 'connectEnd',
82+
time: [1574120165, 429803070],
83+
},
7584
{
7685
name: 'requestStart',
7786
time: [1574120165, 435513070],
7887
},
79-
{ name: 'responseStart', time: [1574120165, 436923070] },
88+
{
89+
name: 'responseStart',
90+
time: [1574120165, 436923070],
91+
},
8092
{
8193
name: 'responseEnd',
8294
time: [1574120165, 438688070],
@@ -91,6 +103,9 @@ export const mockedReadableSpan: ReadableSpan = {
91103
})
92104
),
93105
instrumentationLibrary: { name: 'default', version: '0.0.1' },
106+
droppedAttributesCount: 0,
107+
droppedEventsCount: 0,
108+
droppedLinksCount: 0,
94109
};
95110

96111
export function ensureExportedEventsAreCorrect(events: IEvent[]) {

experimental/packages/exporter-trace-otlp-http/test/traceHelper.ts

+28-4
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,34 @@ export const mockedReadableSpan: ReadableSpan = {
7272
},
7373
],
7474
events: [
75-
{ name: 'fetchStart', time: [1574120165, 429803070] },
75+
{
76+
name: 'fetchStart',
77+
time: [1574120165, 429803070],
78+
},
7679
{
7780
name: 'domainLookupStart',
7881
time: [1574120165, 429803070],
7982
},
80-
{ name: 'domainLookupEnd', time: [1574120165, 429803070] },
83+
{
84+
name: 'domainLookupEnd',
85+
time: [1574120165, 429803070],
86+
},
8187
{
8288
name: 'connectStart',
8389
time: [1574120165, 429803070],
8490
},
85-
{ name: 'connectEnd', time: [1574120165, 429803070] },
91+
{
92+
name: 'connectEnd',
93+
time: [1574120165, 429803070],
94+
},
8695
{
8796
name: 'requestStart',
8897
time: [1574120165, 435513070],
8998
},
90-
{ name: 'responseStart', time: [1574120165, 436923070] },
99+
{
100+
name: 'responseStart',
101+
time: [1574120165, 436923070],
102+
},
91103
{
92104
name: 'responseEnd',
93105
time: [1574120165, 438688070],
@@ -102,6 +114,9 @@ export const mockedReadableSpan: ReadableSpan = {
102114
})
103115
),
104116
instrumentationLibrary: { name: 'default', version: '0.0.1' },
117+
droppedAttributesCount: 0,
118+
droppedEventsCount: 0,
119+
droppedLinksCount: 0,
105120
};
106121

107122
export const mockedResources: Resource[] = [
@@ -142,6 +157,9 @@ export const basicTrace: ReadableSpan[] = [
142157
duration: [0, 8885000],
143158
resource: mockedResources[0],
144159
instrumentationLibrary: mockedInstrumentationLibraries[0],
160+
droppedAttributesCount: 0,
161+
droppedEventsCount: 0,
162+
droppedLinksCount: 0,
145163
},
146164
{
147165
name: 'span2',
@@ -164,6 +182,9 @@ export const basicTrace: ReadableSpan[] = [
164182
duration: [0, 8775000],
165183
resource: mockedResources[0],
166184
instrumentationLibrary: mockedInstrumentationLibraries[0],
185+
droppedAttributesCount: 0,
186+
droppedEventsCount: 0,
187+
droppedLinksCount: 0,
167188
},
168189
{
169190
name: 'span3',
@@ -186,6 +207,9 @@ export const basicTrace: ReadableSpan[] = [
186207
duration: [0, 8775000],
187208
resource: mockedResources[0],
188209
instrumentationLibrary: mockedInstrumentationLibraries[0],
210+
droppedAttributesCount: 0,
211+
droppedEventsCount: 0,
212+
droppedLinksCount: 0,
189213
},
190214
];
191215

experimental/packages/exporter-trace-otlp-proto/test/traceHelper.ts

+19-4
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,34 @@ export const mockedReadableSpan: ReadableSpan = {
5959
},
6060
],
6161
events: [
62-
{ name: 'fetchStart', time: [1574120165, 429803070] },
62+
{
63+
name: 'fetchStart',
64+
time: [1574120165, 429803070],
65+
},
6366
{
6467
name: 'domainLookupStart',
6568
time: [1574120165, 429803070],
6669
},
67-
{ name: 'domainLookupEnd', time: [1574120165, 429803070] },
70+
{
71+
name: 'domainLookupEnd',
72+
time: [1574120165, 429803070],
73+
},
6874
{
6975
name: 'connectStart',
7076
time: [1574120165, 429803070],
7177
},
72-
{ name: 'connectEnd', time: [1574120165, 429803070] },
78+
{
79+
name: 'connectEnd',
80+
time: [1574120165, 429803070],
81+
},
7382
{
7483
name: 'requestStart',
7584
time: [1574120165, 435513070],
7685
},
77-
{ name: 'responseStart', time: [1574120165, 436923070] },
86+
{
87+
name: 'responseStart',
88+
time: [1574120165, 436923070],
89+
},
7890
{
7991
name: 'responseEnd',
8092
time: [1574120165, 438688070],
@@ -87,6 +99,9 @@ export const mockedReadableSpan: ReadableSpan = {
8799
cost: 112.12,
88100
}),
89101
instrumentationLibrary: { name: 'default', version: '0.0.1' },
102+
droppedAttributesCount: 0,
103+
droppedEventsCount: 0,
104+
droppedLinksCount: 0,
90105
};
91106

92107
export function ensureProtoEventsAreCorrect(events: IEvent[]) {

experimental/packages/otlp-grpc-exporter-base/test/traceHelper.ts

+19-4
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,34 @@ export const mockedReadableSpan: ReadableSpan = {
6161
},
6262
],
6363
events: [
64-
{ name: 'fetchStart', time: [1574120165, 429803070] },
64+
{
65+
name: 'fetchStart',
66+
time: [1574120165, 429803070],
67+
},
6568
{
6669
name: 'domainLookupStart',
6770
time: [1574120165, 429803070],
6871
},
69-
{ name: 'domainLookupEnd', time: [1574120165, 429803070] },
72+
{
73+
name: 'domainLookupEnd',
74+
time: [1574120165, 429803070],
75+
},
7076
{
7177
name: 'connectStart',
7278
time: [1574120165, 429803070],
7379
},
74-
{ name: 'connectEnd', time: [1574120165, 429803070] },
80+
{
81+
name: 'connectEnd',
82+
time: [1574120165, 429803070],
83+
},
7584
{
7685
name: 'requestStart',
7786
time: [1574120165, 435513070],
7887
},
79-
{ name: 'responseStart', time: [1574120165, 436923070] },
88+
{
89+
name: 'responseStart',
90+
time: [1574120165, 436923070],
91+
},
8092
{
8193
name: 'responseEnd',
8294
time: [1574120165, 438688070],
@@ -91,6 +103,9 @@ export const mockedReadableSpan: ReadableSpan = {
91103
})
92104
),
93105
instrumentationLibrary: { name: 'default', version: '0.0.1' },
106+
droppedAttributesCount: 0,
107+
droppedEventsCount: 0,
108+
droppedLinksCount: 0,
94109
};
95110

96111
export function ensureExportedEventsAreCorrect(events: IEvent[]) {

experimental/packages/otlp-transformer/src/trace/internal.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@ export function sdkSpanToOtlpSpan(span: ReadableSpan, useHex?: boolean): ISpan {
3939
startTimeUnixNano: hrTimeToNanoseconds(span.startTime),
4040
endTimeUnixNano: hrTimeToNanoseconds(span.endTime),
4141
attributes: toAttributes(span.attributes),
42-
droppedAttributesCount: 0,
42+
droppedAttributesCount: span.droppedAttributesCount,
4343
events: span.events.map(toOtlpSpanEvent),
44-
droppedEventsCount: 0,
44+
droppedEventsCount: span.droppedEventsCount,
4545
status: {
4646
// API and proto enums share the same values
4747
code: status.code as unknown as EStatusCode,
4848
message: status.message,
4949
},
5050
links: span.links.map(link => toOtlpLink(link, useHex)),
51-
droppedLinksCount: 0,
51+
droppedLinksCount: span.droppedLinksCount,
5252
};
5353
}
5454

@@ -62,7 +62,7 @@ export function toOtlpLink(link: Link, useHex?: boolean): ILink {
6262
? link.context.traceId
6363
: core.hexToBase64(link.context.traceId),
6464
traceState: link.context.traceState?.serialize(),
65-
droppedAttributesCount: 0,
65+
droppedAttributesCount: link.droppedAttributesCount || 0,
6666
};
6767
}
6868

@@ -73,6 +73,6 @@ export function toOtlpSpanEvent(timedEvent: TimedEvent): IEvent {
7373
: [],
7474
name: timedEvent.name,
7575
timeUnixNano: hrTimeToNanoseconds(timedEvent.time),
76-
droppedAttributesCount: 0,
76+
droppedAttributesCount: timedEvent.droppedAttributesCount || 0,
7777
};
7878
}

experimental/packages/otlp-transformer/test/trace.test.ts

+3
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ describe('Trace', () => {
178178
status: {
179179
code: SpanStatusCode.OK,
180180
},
181+
droppedAttributesCount: 0,
182+
droppedEventsCount: 0,
183+
droppedLinksCount: 0,
181184
};
182185
});
183186

packages/opentelemetry-core/src/utils/environment.ts

+9
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ const ENVIRONMENT_NUMBERS_KEYS = [
4747
'OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT',
4848
'OTEL_SPAN_EVENT_COUNT_LIMIT',
4949
'OTEL_SPAN_LINK_COUNT_LIMIT',
50+
'OTEL_SPAN_ATTRIBUTE_PER_EVENT_COUNT_LIMIT',
51+
'OTEL_SPAN_ATTRIBUTE_PER_LINK_COUNT_LIMIT',
5052
'OTEL_EXPORTER_OTLP_TIMEOUT',
5153
'OTEL_EXPORTER_OTLP_TRACES_TIMEOUT',
5254
'OTEL_EXPORTER_OTLP_METRICS_TIMEOUT',
@@ -131,6 +133,9 @@ export const DEFAULT_ATTRIBUTE_VALUE_LENGTH_LIMIT = Infinity;
131133

132134
export const DEFAULT_ATTRIBUTE_COUNT_LIMIT = 128;
133135

136+
export const DEFAULT_SPAN_ATTRIBUTE_PER_EVENT_COUNT_LIMIT = 128;
137+
export const DEFAULT_SPAN_ATTRIBUTE_PER_LINK_COUNT_LIMIT = 128;
138+
134139
/**
135140
* Default environment variables
136141
*/
@@ -172,6 +177,10 @@ export const DEFAULT_ENVIRONMENT: Required<ENVIRONMENT> = {
172177
OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT: DEFAULT_ATTRIBUTE_COUNT_LIMIT,
173178
OTEL_SPAN_EVENT_COUNT_LIMIT: 128,
174179
OTEL_SPAN_LINK_COUNT_LIMIT: 128,
180+
OTEL_SPAN_ATTRIBUTE_PER_EVENT_COUNT_LIMIT:
181+
DEFAULT_SPAN_ATTRIBUTE_PER_EVENT_COUNT_LIMIT,
182+
OTEL_SPAN_ATTRIBUTE_PER_LINK_COUNT_LIMIT:
183+
DEFAULT_SPAN_ATTRIBUTE_PER_LINK_COUNT_LIMIT,
175184
OTEL_TRACES_EXPORTER: '',
176185
OTEL_TRACES_SAMPLER: TracesSamplerValues.ParentBasedAlwaysOn,
177186
OTEL_TRACES_SAMPLER_ARG: '',

packages/opentelemetry-exporter-jaeger/src/transform.ts

+30
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,30 @@ export function spanToThrift(span: ReadableSpan): ThriftSpan {
8686
});
8787
}
8888

89+
/* Add droppedAttributesCount as a tag */
90+
if (span.droppedAttributesCount) {
91+
tags.push({
92+
key: 'otel.dropped_attributes_count',
93+
value: toTagValue(span.droppedAttributesCount),
94+
});
95+
}
96+
97+
/* Add droppedEventsCount as a tag */
98+
if (span.droppedEventsCount) {
99+
tags.push({
100+
key: 'otel.dropped_events_count',
101+
value: toTagValue(span.droppedEventsCount),
102+
});
103+
}
104+
105+
/* Add droppedLinksCount as a tag */
106+
if (span.droppedLinksCount) {
107+
tags.push({
108+
key: 'otel.dropped_links_count',
109+
value: toTagValue(span.droppedLinksCount),
110+
});
111+
}
112+
89113
const spanTags: ThriftTag[] = ThriftUtils.getThriftTags(tags);
90114

91115
const logs = span.events.map((event): Log => {
@@ -96,6 +120,12 @@ export function spanToThrift(span: ReadableSpan): ThriftSpan {
96120
fields.push({ key: attr, value: toTagValue(attrs[attr]) })
97121
);
98122
}
123+
if (event.droppedAttributesCount) {
124+
fields.push({
125+
key: 'otel.event.dropped_attributes_count',
126+
value: event.droppedAttributesCount,
127+
});
128+
}
99129
return { timestamp: hrTimeToMilliseconds(event.time), fields };
100130
});
101131
const spanLogs: ThriftLog[] = ThriftUtils.getThriftLogs(logs);

packages/opentelemetry-exporter-jaeger/test/jaeger.test.ts

+3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ describe('JaegerExporter', () => {
5353
name: 'default',
5454
version: '0.0.1',
5555
},
56+
droppedAttributesCount: 0,
57+
droppedEventsCount: 0,
58+
droppedLinksCount: 0,
5659
};
5760
describe('constructor', () => {
5861
afterEach(() => {

0 commit comments

Comments
 (0)