Skip to content

Commit

Permalink
Pass span context in console instrumentation if present
Browse files Browse the repository at this point in the history
  • Loading branch information
mxab committed Jul 1, 2024
1 parent 3f20032 commit 869afe8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Next

- Fix (`@grafana/faro-web-sdk`): span context is now passed to pushLogs in the console instrumentation (#632).

## 1.8.0

- Feature (`@grafana/faro-web-sdk`): track `web vitals` attribution (#595).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class ConsoleInstrumentation extends BaseInstrumentation {
/* eslint-disable-next-line no-console */
console[level] = (...args) => {
try {
this.api.pushLog(args, { level });
this.api.pushLog(args, { level, spanContext: this.currentSpanContext() });
} catch (err) {
this.logError(err);
} finally {
Expand All @@ -30,4 +30,8 @@ export class ConsoleInstrumentation extends BaseInstrumentation {
};
});
}
private currentSpanContext(): { traceId: string; spanId: string } | undefined {
const traceContext = this.api.getTraceContext();
return traceContext ? { traceId: traceContext.trace_id, spanId: traceContext.span_id } : undefined;
}
}

0 comments on commit 869afe8

Please sign in to comment.