Skip to content

Commit

Permalink
record attributes, errors
Browse files Browse the repository at this point in the history
  • Loading branch information
rjawesome committed Dec 30, 2023
1 parent cd750dd commit 6fce629
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/telemetry.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Sentry from "@sentry/node";
import Debug from "debug";
import opentelemetry, { Span as OtelSpan, Context as OtelContext } from '@opentelemetry/api';
import opentelemetry, { Span as OtelSpan, Context as OtelContext, SpanStatusCode } from '@opentelemetry/api';
const debug = Debug("bte:telemetry-interface");

const reassurance = "This doesn't affect execution";
Expand All @@ -25,6 +25,7 @@ class Span {
setData(key: string, data: unknown) {
try {
this.span?.setData(key, data);
this.otelSpan?.setAttribute(`bte.${key}`, typeof data === 'object' ? JSON.stringify(data) : data as any);
} catch (error) {
debug(`Sentry setData error. ${reassurance}`);
debug(error);
Expand All @@ -48,6 +49,11 @@ export class Telemetry {
}
static captureException(error: Error) {
Sentry.captureException(error);

if (this.getOtelSpan()) {
this.getOtelSpan().recordException(error);
this.getOtelSpan().setStatus({ code: SpanStatusCode.ERROR });
}
}
static addBreadcrumb(breadcrumb?: Sentry.Breadcrumb) {
try {
Expand Down

0 comments on commit 6fce629

Please sign in to comment.