Skip to content

Commit

Permalink
Handle scenario where span exists outside the context of a trace.
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanatkinson committed Jun 3, 2024
1 parent ab3bf0c commit d1feee3
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions js/core/src/tracing/instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ export async function runInNewSpan<T>(

opts.metadata.path = decoratePathWithSubtype(opts.metadata);
if (pathCount == getCurrentPathCount()) {
getCurrentTrace().paths?.add(opts.metadata.path);
traceMetadataAls.getStore()?.paths?.add(opts.metadata.path);
}

return output;
} catch (e) {
opts.metadata.path = decoratePathWithSubtype(opts.metadata);
getCurrentTrace().paths?.add(opts.metadata.path);
traceMetadataAls.getStore()?.paths?.add(opts.metadata.path);
opts.metadata.state = 'error';
otSpan.setStatus({
code: SpanStatusCode.ERROR,
Expand Down Expand Up @@ -188,16 +188,8 @@ function getCurrentSpan(): SpanMetadata {
return step;
}

function getCurrentTrace(): TraceMetadata {
const trace = traceMetadataAls.getStore();
if (!trace) {
throw new Error('running outside trace context');
}
return trace;
}

function getCurrentPathCount(): number {
return getCurrentTrace().paths?.size || 0;
return traceMetadataAls.getStore()?.paths?.size || 0;
}

function decoratePathWithSubtype(metadata: SpanMetadata): string {
Expand Down

0 comments on commit d1feee3

Please sign in to comment.