Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sdk-trace-base): add dropped attributes and events count on span #3576

Merged
merged 36 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
b2c9f40
feat(sdk-trace-base): add dropped attributes and events count on span
mohitk05 Jan 27, 2023
55a26b8
feat(sdk-trace-base): sync with main
mohitk05 Jan 27, 2023
b3e0307
feat(sdk-trace-base): [revert] sync with main
mohitk05 Jan 27, 2023
842143d
Merge branch 'main' into feat/span-dropped-counts
mohitk05 Jan 27, 2023
bab88a1
feat(sdk-trace-base): fix tests, make both counts truthy
mohitk05 Jan 28, 2023
33378f8
Merge branch 'feat/span-dropped-counts' of github.com:mohitk05/opente…
mohitk05 Jan 28, 2023
28666c6
Merge branch 'main' into feat/span-dropped-counts
mohitk05 Jan 30, 2023
17213bd
feat(sdk-trace-base): Update dropped counts type to number
mohitk05 Jan 31, 2023
81e35f6
Merge branch 'open-telemetry:main' into feat/span-dropped-counts
mohitk05 Jan 31, 2023
4eb895c
feat(sdk-trace-base): Merge branch 'feat/span-dropped-counts' of gith…
mohitk05 Jan 31, 2023
a8c1454
Merge branch 'main' into feat/span-dropped-counts
mohitk05 Feb 1, 2023
dc78fa3
feat(sdk-trace-base): Use exposed counts on ReadableSpan in jaeger an…
mohitk05 Feb 5, 2023
08d75e4
feat(sdk-trace-base): Merge branch 'feat/span-dropped-counts' of gith…
mohitk05 Feb 5, 2023
4a3105e
Merge branch 'main' into feat/span-dropped-counts
dyladan Feb 9, 2023
411c1cb
feat(sdk-trace-base): WIP - revert tsconfig, add new attribute limits
mohitk05 Feb 9, 2023
32300bf
feat(sdk-trace-base): Update attribute truncate method
mohitk05 Feb 9, 2023
5439f4e
Merge branch 'main' into feat/span-dropped-counts
dyladan Feb 24, 2023
0365435
Fix bad conflict resolution
dyladan Feb 24, 2023
8a486c7
Remove unused import
dyladan Feb 24, 2023
f9d935c
chore: lint
dyladan Feb 24, 2023
036190f
Merge branch 'main' into feat/span-dropped-counts
mohitk05 Feb 28, 2023
18d82c6
feat(sdk-trace-base): Remove dropped event attributes logic, add Jaeg…
mohitk05 Feb 28, 2023
f674906
feat(sdk-trace-base): Undo formatting in changelog
mohitk05 Feb 28, 2023
577b174
fix(changelog): Update experimental changelog
mohitk05 Feb 28, 2023
6dadccb
Update packages/opentelemetry-sdk-trace-base/src/Span.ts
mohitk05 Mar 1, 2023
1748267
Update packages/opentelemetry-sdk-trace-base/src/Span.ts
mohitk05 Mar 1, 2023
cc632ef
Merge branch 'main' into feat/span-dropped-counts
mohitk05 Mar 1, 2023
69b407f
fix(sdk-trace-base): Resolve review comments
mohitk05 Mar 1, 2023
85b2038
Merge branch 'main' into feat/span-dropped-counts
Flarna Mar 1, 2023
f260436
fix(sdk-trace-base): Fix failing tests
mohitk05 Mar 1, 2023
1db099c
Merge branch 'main' into feat/span-dropped-counts
mohitk05 Mar 1, 2023
0239413
fix(sdk-trace-base): make droppedAttributesCount on event optional
mohitk05 Mar 2, 2023
f40a11b
Merge branch 'main' into feat/span-dropped-counts
mohitk05 Mar 2, 2023
60bc89f
Merge branch 'main' into feat/span-dropped-counts
Flarna Mar 3, 2023
141172e
Merge branch 'main' into feat/span-dropped-counts
mohitk05 Mar 7, 2023
2221770
fix(changelog): Update changelog files
mohitk05 Mar 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ export const mockedReadableSpan: ReadableSpan = {
})
),
instrumentationLibrary: { name: 'default', version: '0.0.1' },
droppedAttributesCount: 0,
droppedEventsCount: 0,
droppedLinksCount: 0,
};

export function ensureExportedEventsAreCorrect(events: IEvent[]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ export const mockedReadableSpan: ReadableSpan = {
})
),
instrumentationLibrary: { name: 'default', version: '0.0.1' },
droppedAttributesCount: 0,
droppedEventsCount: 0,
droppedLinksCount: 0,
};

export const mockedResources: Resource[] = [
Expand Down Expand Up @@ -142,6 +145,9 @@ export const basicTrace: ReadableSpan[] = [
duration: [0, 8885000],
resource: mockedResources[0],
instrumentationLibrary: mockedInstrumentationLibraries[0],
droppedAttributesCount: 0,
droppedEventsCount: 0,
droppedLinksCount: 0,
},
{
name: 'span2',
Expand All @@ -164,6 +170,9 @@ export const basicTrace: ReadableSpan[] = [
duration: [0, 8775000],
resource: mockedResources[0],
instrumentationLibrary: mockedInstrumentationLibraries[0],
droppedAttributesCount: 0,
droppedEventsCount: 0,
droppedLinksCount: 0,
},
{
name: 'span3',
Expand All @@ -186,6 +195,9 @@ export const basicTrace: ReadableSpan[] = [
duration: [0, 8775000],
resource: mockedResources[0],
instrumentationLibrary: mockedInstrumentationLibraries[0],
droppedAttributesCount: 0,
droppedEventsCount: 0,
droppedLinksCount: 0,
},
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ export const mockedReadableSpan: ReadableSpan = {
cost: 112.12,
}),
instrumentationLibrary: { name: 'default', version: '0.0.1' },
droppedAttributesCount: 0,
droppedEventsCount: 0,
droppedLinksCount: 0,
};

export function ensureProtoEventsAreCorrect(events: IEvent[]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ export const mockedReadableSpan: ReadableSpan = {
})
),
instrumentationLibrary: { name: 'default', version: '0.0.1' },
droppedAttributesCount: 0,
droppedEventsCount: 0,
droppedLinksCount: 0,
};

export function ensureExportedEventsAreCorrect(events: IEvent[]) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"extends": "../../../tsconfig.base.esnext.json",
"compilerOptions": {
"allowJs": true,
dyladan marked this conversation as resolved.
Show resolved Hide resolved
"outDir": "build/esnext",
"rootDir": "src",
"outDir": "build/esnext",
"tsBuildInfoFile": "build/esnext/tsconfig.esnext.tsbuildinfo"
},
"include": [
Expand Down
3 changes: 3 additions & 0 deletions experimental/packages/otlp-transformer/test/trace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ describe('Trace', () => {
status: {
code: SpanStatusCode.OK,
},
droppedAttributesCount: 0,
droppedEventsCount: 0,
droppedLinksCount: 0,
};
});

Expand Down
3 changes: 3 additions & 0 deletions packages/opentelemetry-exporter-jaeger/test/jaeger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ describe('JaegerExporter', () => {
name: 'default',
version: '0.0.1',
},
droppedAttributesCount: 0,
droppedEventsCount: 0,
droppedLinksCount: 0,
};
describe('constructor', () => {
afterEach(() => {
Expand Down
15 changes: 15 additions & 0 deletions packages/opentelemetry-exporter-jaeger/test/transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ describe('transform', () => {
name: 'default',
version: '0.0.1',
},
droppedAttributesCount: 0,
droppedEventsCount: 0,
droppedLinksCount: 0,
};

const thriftSpan = spanToThrift(readableSpan);
Expand Down Expand Up @@ -179,6 +182,9 @@ describe('transform', () => {
name: 'default',
version: '0.0.1',
},
droppedAttributesCount: 0,
droppedEventsCount: 0,
droppedLinksCount: 0,
};

const thriftSpan = spanToThrift(readableSpan);
Expand Down Expand Up @@ -246,6 +252,9 @@ describe('transform', () => {
name: 'default',
version: '0.0.1',
},
droppedAttributesCount: 0,
droppedEventsCount: 0,
droppedLinksCount: 0,
};

const thriftSpan = spanToThrift(readableSpan);
Expand Down Expand Up @@ -291,6 +300,9 @@ describe('transform', () => {
name: 'default',
version: '0.0.1',
},
droppedAttributesCount: 0,
droppedEventsCount: 0,
droppedLinksCount: 0,
};

const thriftSpan = spanToThrift(readableSpan);
Expand Down Expand Up @@ -353,6 +365,9 @@ describe('transform', () => {
name: 'default',
version: '0.0.1',
},
droppedAttributesCount: 0,
droppedEventsCount: 0,
droppedLinksCount: 0,
};
let thriftSpan = spanToThrift(readableSpan);
assert.strictEqual(
Expand Down
3 changes: 3 additions & 0 deletions packages/opentelemetry-exporter-zipkin/test/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ export const mockedReadableSpan: ReadableSpan = {
cost: 112.12,
}),
instrumentationLibrary: { name: 'default', version: '0.0.1' },
droppedAttributesCount: 0,
droppedEventsCount: 0,
droppedLinksCount: 0,
};

export function ensureHeadersContain(
Expand Down
21 changes: 21 additions & 0 deletions packages/opentelemetry-exporter-zipkin/test/node/zipkin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ function getReadableSpan() {
events: [],
resource: Resource.empty(),
instrumentationLibrary: { name: 'default', version: '0.0.1' },
droppedAttributesCount: 0,
droppedEventsCount: 0,
droppedLinksCount: 0,
};
return readableSpan;
}
Expand Down Expand Up @@ -164,6 +167,9 @@ describe('Zipkin Exporter - node', () => {
],
resource: Resource.empty(),
instrumentationLibrary: { name: 'default', version: '0.0.1' },
droppedAttributesCount: 0,
droppedEventsCount: 0,
droppedLinksCount: 0,
};
const span2: ReadableSpan = {
name: 'my-span',
Expand All @@ -187,6 +193,9 @@ describe('Zipkin Exporter - node', () => {
events: [],
resource: Resource.empty(),
instrumentationLibrary: { name: 'default', version: '0.0.1' },
droppedAttributesCount: 0,
droppedEventsCount: 0,
droppedLinksCount: 0,
};

const exporter = new ZipkinExporter({
Expand Down Expand Up @@ -379,6 +388,9 @@ describe('Zipkin Exporter - node', () => {
[SemanticResourceAttributes.SERVICE_NAME]: resource_service_name,
}),
instrumentationLibrary: { name: 'default', version: '0.0.1' },
droppedAttributesCount: 0,
droppedEventsCount: 0,
droppedLinksCount: 0,
};
const span2: ReadableSpan = {
name: 'my-span',
Expand All @@ -402,6 +414,9 @@ describe('Zipkin Exporter - node', () => {
[SemanticResourceAttributes.SERVICE_NAME]: resource_service_name_prime,
}),
instrumentationLibrary: { name: 'default', version: '0.0.1' },
droppedAttributesCount: 0,
droppedEventsCount: 0,
droppedLinksCount: 0,
};

const exporter = new ZipkinExporter({});
Expand Down Expand Up @@ -467,6 +482,9 @@ describe('Zipkin Exporter - node', () => {
],
resource: Resource.empty(),
instrumentationLibrary: { name: 'default', version: '0.0.1' },
droppedAttributesCount: 0,
droppedEventsCount: 0,
droppedLinksCount: 0,
};
const span2: ReadableSpan = {
name: 'my-span',
Expand All @@ -490,6 +508,9 @@ describe('Zipkin Exporter - node', () => {
events: [],
resource: Resource.empty(),
instrumentationLibrary: { name: 'default', version: '0.0.1' },
droppedAttributesCount: 0,
droppedEventsCount: 0,
droppedLinksCount: 0,
};

const exporter = new ZipkinExporter({});
Expand Down
25 changes: 17 additions & 8 deletions packages/opentelemetry-sdk-trace-base/src/Span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ export class Span implements APISpan, ReadableSpan {
readonly startTime: HrTime;
readonly resource: Resource;
readonly instrumentationLibrary: InstrumentationLibrary;
droppedAttributesCount: number = 0;
droppedEventsCount: number = 0;
droppedLinksCount: number = 0;

name: string;
status: SpanStatus = {
code: SpanStatusCode.UNSET,
Expand Down Expand Up @@ -141,6 +145,7 @@ export class Span implements APISpan, ReadableSpan {
this._spanLimits.attributeCountLimit! &&
!Object.prototype.hasOwnProperty.call(this.attributes, key)
) {
this.droppedAttributesCount += 1;
return this;
}
this.attributes[key] = this._truncateToSize(value);
Expand All @@ -167,14 +172,6 @@ export class Span implements APISpan, ReadableSpan {
timeStamp?: TimeInput
): this {
if (this._isSpanEnded()) return this;
if (this._spanLimits.eventCountLimit === 0) {
diag.warn('No events allowed.');
return this;
}
if (this.events.length >= this._spanLimits.eventCountLimit!) {
diag.warn('Dropping extra events.');
this.events.shift();
}

if (isTimeInput(attributesOrStartTime)) {
if (!isTimeInput(timeStamp)) {
Expand All @@ -184,6 +181,18 @@ export class Span implements APISpan, ReadableSpan {
}

const attributes = sanitizeAttributes(attributesOrStartTime);

if (this._spanLimits.eventCountLimit === 0) {
diag.warn('No events allowed.');
this.droppedEventsCount += 1;
return this;
}
if (this.events.length >= this._spanLimits.eventCountLimit!) {
diag.warn('Dropping extra events.');
this.events.shift();
this.droppedEventsCount += 1;
}

this.events.push({
name,
attributes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,7 @@ export interface ReadableSpan {
readonly ended: boolean;
readonly resource: Resource;
readonly instrumentationLibrary: InstrumentationLibrary;
readonly droppedAttributesCount: number;
readonly droppedEventsCount: number;
readonly droppedLinksCount: number;
dyladan marked this conversation as resolved.
Show resolved Hide resolved
}
20 changes: 20 additions & 0 deletions packages/opentelemetry-sdk-trace-base/test/common/Span.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,10 @@ describe('Span', () => {
assert.strictEqual(span.attributes['foo99'], 'bar99');
assert.strictEqual(span.attributes['foo149'], undefined);
});

it('should store the count of dropped attributes in droppedAttributesCount', () => {
assert.strictEqual(span.droppedAttributesCount, 50);
});
});

describe('when "attributeValueLengthLimit" option defined', () => {
Expand Down Expand Up @@ -791,6 +795,22 @@ describe('Span', () => {
assert.strictEqual(span.events[span.events.length - 1].name, 'sent149');
});

it('should store the count of dropped events in droppedEventsCount', () => {
const span = new Span(
tracer,
ROOT_CONTEXT,
name,
spanContext,
SpanKind.CLIENT
);
for (let i = 0; i < 150; i++) {
span.addEvent('sent' + i);
}
span.end();

assert.strictEqual(span.droppedEventsCount, 50);
});

it('should add no event', () => {
const tracer = new BasicTracerProvider({
spanLimits: {
Expand Down