Skip to content

Commit 59c35a6

Browse files
qianl15maxdml
andauthored
Handle attributes safely when ending spans (#963) (#965)
Ensure attributes exists on the span before setting them in `endSpan` Co-authored-by: Max dml <[email protected]>
1 parent a84bb82 commit 59c35a6

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/telemetry/traces.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class Tracer {
1616
[SemanticResourceAttributes.SERVICE_NAME]: 'dbos',
1717
}),
1818
});
19-
this.tracer.register();
19+
this.tracer.register(); // this is a no-op if another tracer provider was already registered
2020
this.applicationID = globalParams.appID;
2121
this.executorID = globalParams.executorID; // for consistency with src/context.ts
2222
}
@@ -39,12 +39,14 @@ export class Tracer {
3939
}
4040

4141
endSpan(span: Span) {
42-
span.end(hrTime(performance.now()));
43-
span.attributes.applicationID = this.applicationID;
44-
span.attributes.applicationVersion = globalParams.appVersion;
45-
if (!('executorID' in span.attributes)) {
46-
span.attributes.executorID = this.executorID;
42+
span.setAttributes({
43+
applicationID: this.applicationID,
44+
applicationVersion: globalParams.appVersion,
45+
});
46+
if (span.attributes && !('executorID' in span.attributes)) {
47+
span.setAttribute('executorID', this.executorID);
4748
}
49+
span.end(hrTime(performance.now()));
4850
this.telemetryCollector.push(span as ReadableSpan);
4951
}
5052
}

0 commit comments

Comments
 (0)