Skip to content

Commit 7c7d4e6

Browse files
committed
align span & function names
Use regular `Span` type from `@opentelemetry/api` wherever possible.
1 parent 613269d commit 7c7d4e6

26 files changed

+235
-182
lines changed

packages/node-experimental/src/integrations/express.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Instrumentation } from '@opentelemetry/instrumentation';
22
import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express';
33
import type { Integration } from '@sentry/types';
44

5-
import { addOriginToOtelSpan } from '../utils/addOriginToSpan';
5+
import { addOriginToSpan } from '../utils/addOriginToSpan';
66
import { NodePerformanceIntegration } from './NodePerformanceIntegration';
77

88
/**
@@ -31,7 +31,7 @@ export class Express extends NodePerformanceIntegration<void> implements Integra
3131
return [
3232
new ExpressInstrumentation({
3333
requestHook(span) {
34-
addOriginToOtelSpan(span, 'auto.http.otel.express');
34+
addOriginToSpan(span, 'auto.http.otel.express');
3535
},
3636
}),
3737
];

packages/node-experimental/src/integrations/fastify.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Instrumentation } from '@opentelemetry/instrumentation';
22
import { FastifyInstrumentation } from '@opentelemetry/instrumentation-fastify';
33
import type { Integration } from '@sentry/types';
44

5-
import { addOriginToOtelSpan } from '../utils/addOriginToSpan';
5+
import { addOriginToSpan } from '../utils/addOriginToSpan';
66
import { NodePerformanceIntegration } from './NodePerformanceIntegration';
77

88
/**
@@ -31,7 +31,7 @@ export class Fastify extends NodePerformanceIntegration<void> implements Integra
3131
return [
3232
new FastifyInstrumentation({
3333
requestHook(span) {
34-
addOriginToOtelSpan(span, 'auto.http.otel.fastify');
34+
addOriginToSpan(span, 'auto.http.otel.fastify');
3535
},
3636
}),
3737
];

packages/node-experimental/src/integrations/graphql.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Instrumentation } from '@opentelemetry/instrumentation';
22
import { GraphQLInstrumentation } from '@opentelemetry/instrumentation-graphql';
33
import type { Integration } from '@sentry/types';
44

5-
import { addOriginToOtelSpan } from '../utils/addOriginToSpan';
5+
import { addOriginToSpan } from '../utils/addOriginToSpan';
66
import { NodePerformanceIntegration } from './NodePerformanceIntegration';
77

88
/**
@@ -32,7 +32,7 @@ export class GraphQL extends NodePerformanceIntegration<void> implements Integra
3232
new GraphQLInstrumentation({
3333
ignoreTrivialResolveSpans: true,
3434
responseHook(span) {
35-
addOriginToOtelSpan(span, 'auto.graphql.otel.graphql');
35+
addOriginToSpan(span, 'auto.graphql.otel.graphql');
3636
},
3737
}),
3838
];

packages/node-experimental/src/integrations/http.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { Span } from '@opentelemetry/api';
12
import { SpanKind } from '@opentelemetry/api';
23
import { registerInstrumentations } from '@opentelemetry/instrumentation';
34
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
@@ -7,12 +8,12 @@ import { stringMatchesSomePattern } from '@sentry/utils';
78
import type { ClientRequest, IncomingMessage, ServerResponse } from 'http';
89

910
import { OTEL_ATTR_ORIGIN } from '../constants';
10-
import { setOtelSpanMetadata } from '../opentelemetry/spanData';
11+
import { setSpanMetadata } from '../opentelemetry/spanData';
1112
import type { NodeExperimentalClient } from '../sdk/client';
1213
import { getCurrentHub } from '../sdk/hub';
13-
import type { OtelSpan } from '../types';
1414
import { getRequestSpanData } from '../utils/getRequestSpanData';
1515
import { getRequestUrl } from '../utils/getRequestUrl';
16+
import { getSpanKind } from '../utils/getSpanKind';
1617

1718
interface HttpOptions {
1819
/**
@@ -128,10 +129,10 @@ export class Http implements Integration {
128129
requireParentforOutgoingSpans: true,
129130
requireParentforIncomingSpans: false,
130131
requestHook: (span, req) => {
131-
this._updateSpan(span as unknown as OtelSpan, req);
132+
this._updateSpan(span, req);
132133
},
133134
responseHook: (span, res) => {
134-
this._addRequestBreadcrumb(span as unknown as OtelSpan, res);
135+
this._addRequestBreadcrumb(span, res);
135136
},
136137
}),
137138
],
@@ -146,17 +147,17 @@ export class Http implements Integration {
146147
}
147148

148149
/** Update the span with data we need. */
149-
private _updateSpan(span: OtelSpan, request: ClientRequest | IncomingMessage): void {
150+
private _updateSpan(span: Span, request: ClientRequest | IncomingMessage): void {
150151
span.setAttribute(OTEL_ATTR_ORIGIN, 'auto.http.otel.http');
151152

152-
if (span.kind === SpanKind.SERVER) {
153-
setOtelSpanMetadata(span, { request });
153+
if (getSpanKind(span) === SpanKind.SERVER) {
154+
setSpanMetadata(span, { request });
154155
}
155156
}
156157

157158
/** Add a breadcrumb for outgoing requests. */
158-
private _addRequestBreadcrumb(span: OtelSpan, response: IncomingMessage | ServerResponse): void {
159-
if (!this._breadcrumbs || span.kind !== SpanKind.CLIENT) {
159+
private _addRequestBreadcrumb(span: Span, response: IncomingMessage | ServerResponse): void {
160+
if (!this._breadcrumbs || getSpanKind(span) !== SpanKind.CLIENT) {
160161
return;
161162
}
162163

packages/node-experimental/src/integrations/mongo.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Instrumentation } from '@opentelemetry/instrumentation';
22
import { MongoDBInstrumentation } from '@opentelemetry/instrumentation-mongodb';
33
import type { Integration } from '@sentry/types';
44

5-
import { addOriginToOtelSpan } from '../utils/addOriginToSpan';
5+
import { addOriginToSpan } from '../utils/addOriginToSpan';
66
import { NodePerformanceIntegration } from './NodePerformanceIntegration';
77

88
/**
@@ -31,7 +31,7 @@ export class Mongo extends NodePerformanceIntegration<void> implements Integrati
3131
return [
3232
new MongoDBInstrumentation({
3333
responseHook(span) {
34-
addOriginToOtelSpan(span, 'auto.db.otel.mongo');
34+
addOriginToSpan(span, 'auto.db.otel.mongo');
3535
},
3636
}),
3737
];

packages/node-experimental/src/integrations/mongoose.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Instrumentation } from '@opentelemetry/instrumentation';
22
import { MongooseInstrumentation } from '@opentelemetry/instrumentation-mongoose';
33
import type { Integration } from '@sentry/types';
44

5-
import { addOriginToOtelSpan } from '../utils/addOriginToSpan';
5+
import { addOriginToSpan } from '../utils/addOriginToSpan';
66
import { NodePerformanceIntegration } from './NodePerformanceIntegration';
77

88
/**
@@ -31,7 +31,7 @@ export class Mongoose extends NodePerformanceIntegration<void> implements Integr
3131
return [
3232
new MongooseInstrumentation({
3333
responseHook(span) {
34-
addOriginToOtelSpan(span, 'auto.db.otel.mongoose');
34+
addOriginToSpan(span, 'auto.db.otel.mongoose');
3535
},
3636
}),
3737
];

packages/node-experimental/src/integrations/mysql2.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Instrumentation } from '@opentelemetry/instrumentation';
22
import { MySQL2Instrumentation } from '@opentelemetry/instrumentation-mysql2';
33
import type { Integration } from '@sentry/types';
44

5-
import { addOriginToOtelSpan } from '../utils/addOriginToSpan';
5+
import { addOriginToSpan } from '../utils/addOriginToSpan';
66
import { NodePerformanceIntegration } from './NodePerformanceIntegration';
77

88
/**
@@ -31,7 +31,7 @@ export class Mysql2 extends NodePerformanceIntegration<void> implements Integrat
3131
return [
3232
new MySQL2Instrumentation({
3333
responseHook(span) {
34-
addOriginToOtelSpan(span, 'auto.db.otel.mysql2');
34+
addOriginToSpan(span, 'auto.db.otel.mysql2');
3535
},
3636
}),
3737
];

packages/node-experimental/src/integrations/postgres.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Instrumentation } from '@opentelemetry/instrumentation';
22
import { PgInstrumentation } from '@opentelemetry/instrumentation-pg';
33
import type { Integration } from '@sentry/types';
44

5-
import { addOriginToOtelSpan } from '../utils/addOriginToSpan';
5+
import { addOriginToSpan } from '../utils/addOriginToSpan';
66
import { NodePerformanceIntegration } from './NodePerformanceIntegration';
77

88
/**
@@ -32,7 +32,7 @@ export class Postgres extends NodePerformanceIntegration<void> implements Integr
3232
new PgInstrumentation({
3333
requireParentSpan: true,
3434
requestHook(span) {
35-
addOriginToOtelSpan(span, 'auto.db.otel.postgres');
35+
addOriginToSpan(span, 'auto.db.otel.postgres');
3636
},
3737
}),
3838
];
Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,50 @@
1-
import type { Span as OtelSpan } from '@opentelemetry/api';
1+
import type { Span } from '@opentelemetry/api';
22
import type { Hub, Scope, TransactionMetadata } from '@sentry/types';
33

44
// We store the parent span, scope & metadata in separate weakmaps, so we can access them for a given span
55
// This way we can enhance the data that an OTEL Span natively gives us
66
// and since we are using weakmaps, we do not need to clean up after ourselves
7-
const otelSpanScope = new WeakMap<OtelSpan, Scope>();
8-
const otelSpanHub = new WeakMap<OtelSpan, Hub>();
9-
const otelSpanParent = new WeakMap<OtelSpan, OtelSpan>();
10-
const otelSpanMetadata = new WeakMap<OtelSpan, Partial<TransactionMetadata>>();
7+
const SpanScope = new WeakMap<Span, Scope>();
8+
const SpanHub = new WeakMap<Span, Hub>();
9+
const SpanParent = new WeakMap<Span, Span>();
10+
const SpanMetadata = new WeakMap<Span, Partial<TransactionMetadata>>();
1111

1212
/** Set the Sentry scope on an OTEL span. */
13-
export function setOtelSpanScope(span: OtelSpan, scope: Scope): void {
14-
otelSpanScope.set(span, scope);
13+
export function setSpanScope(span: Span, scope: Scope): void {
14+
SpanScope.set(span, scope);
1515
}
1616

1717
/** Get the Sentry scope of an OTEL span. */
18-
export function getOtelSpanScope(span: OtelSpan): Scope | undefined {
19-
return otelSpanScope.get(span);
18+
export function getSpanScope(span: Span): Scope | undefined {
19+
return SpanScope.get(span);
2020
}
2121

2222
/** Set the Sentry hub on an OTEL span. */
23-
export function setOtelSpanHub(span: OtelSpan, hub: Hub): void {
24-
otelSpanHub.set(span, hub);
23+
export function setSpanHub(span: Span, hub: Hub): void {
24+
SpanHub.set(span, hub);
2525
}
2626

2727
/** Get the Sentry hub of an OTEL span. */
28-
export function getOtelSpanHub(span: OtelSpan): Hub | undefined {
29-
return otelSpanHub.get(span);
28+
export function getSpanHub(span: Span): Hub | undefined {
29+
return SpanHub.get(span);
3030
}
3131

3232
/** Set the parent OTEL span on an OTEL span. */
33-
export function setOtelSpanParent(span: OtelSpan, parentSpan: OtelSpan): void {
34-
otelSpanParent.set(span, parentSpan);
33+
export function setSpanParent(span: Span, parentSpan: Span): void {
34+
SpanParent.set(span, parentSpan);
3535
}
3636

3737
/** Get the parent OTEL span of an OTEL span. */
38-
export function getOtelSpanParent(span: OtelSpan): OtelSpan | undefined {
39-
return otelSpanParent.get(span);
38+
export function getSpanParent(span: Span): Span | undefined {
39+
return SpanParent.get(span);
4040
}
4141

4242
/** Set metadata for an OTEL span. */
43-
export function setOtelSpanMetadata(span: OtelSpan, metadata: Partial<TransactionMetadata>): void {
44-
otelSpanMetadata.set(span, metadata);
43+
export function setSpanMetadata(span: Span, metadata: Partial<TransactionMetadata>): void {
44+
SpanMetadata.set(span, metadata);
4545
}
4646

4747
/** Get metadata for an OTEL span. */
48-
export function getOtelSpanMetadata(span: OtelSpan): Partial<TransactionMetadata> | undefined {
49-
return otelSpanMetadata.get(span);
48+
export function getSpanMetadata(span: Span): Partial<TransactionMetadata> | undefined {
49+
return SpanMetadata.get(span);
5050
}

0 commit comments

Comments
 (0)