Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/cloudflare/src/opentelemetry/tracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class SentryCloudflareTraceProvider implements TracerProvider {
class SentryCloudflareTracer implements Tracer {
public startSpan(name: string, options?: SpanOptions): Span {
return startInactiveSpan({
name,
...options,
name,
Comment on lines 30 to +31
Copy link
Member

@Lms24 Lms24 Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm it's interesting that options overwrote the name because the SpanOptions type doesn't include name AFAICT. Is Prisma instrumentation incorrectly using the OTel API?
Ahh should have read the PR description more carefully. This is what's supposedly happening (?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what's supposedly happening

Yes, exactly. Usually the name is not set in the options - except in this case.

attributes: {
...options?.attributes,
'sentry.cloudflare_tracer': true,
Expand Down Expand Up @@ -56,8 +56,8 @@ class SentryCloudflareTracer implements Tracer {
const opts = (typeof options === 'object' && options !== null ? options : {}) as SpanOptions;

const spanOpts = {
name,
...opts,
name,
attributes: {
...opts.attributes,
'sentry.cloudflare_tracer': true,
Expand Down
55 changes: 55 additions & 0 deletions packages/cloudflare/test/opentelemetry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,59 @@ describe('opentelemetry compatibility', () => {
}),
]);
});

test('name parameter should take precedence over options.name in startSpan', async () => {
const transactionEvents: TransactionEvent[] = [];

const client = init({
dsn: 'https://username@domain/123',
tracesSampleRate: 1,
beforeSendTransaction: event => {
transactionEvents.push(event);
return null;
},
});

const tracer = trace.getTracer('test');

// Pass options with a different name property - the first parameter should take precedence
// This is important for integrations like Prisma that add prefixes to span names
const span = tracer.startSpan('prisma:client:operation', { name: 'operation' } as any);
span.end();

await client!.flush();

expect(transactionEvents).toHaveLength(1);
const [transactionEvent] = transactionEvents;

expect(transactionEvent?.transaction).toBe('prisma:client:operation');
});

test('name parameter should take precedence over options.name in startActiveSpan', async () => {
const transactionEvents: TransactionEvent[] = [];

const client = init({
dsn: 'https://username@domain/123',
tracesSampleRate: 1,
beforeSendTransaction: event => {
transactionEvents.push(event);
return null;
},
});

const tracer = trace.getTracer('test');

// Pass options with a different name property - the first parameter should take precedence
// This is important for integrations like Prisma that add prefixes to span names
tracer.startActiveSpan('prisma:client:operation', { name: 'operation' } as any, span => {
span.end();
});

await client!.flush();

expect(transactionEvents).toHaveLength(1);
const [transactionEvent] = transactionEvents;

expect(transactionEvent?.transaction).toBe('prisma:client:operation');
});
});
4 changes: 2 additions & 2 deletions packages/deno/src/opentelemetry/tracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class SentryDenoTracer implements Tracer {
const op = this._mapSpanKindToOp(options?.kind);

return startInactiveSpan({
name,
...options,
name,
attributes: {
...options?.attributes,
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'manual',
Expand Down Expand Up @@ -69,8 +69,8 @@ class SentryDenoTracer implements Tracer {
const op = this._mapSpanKindToOp(opts.kind);

const spanOpts = {
name,
...opts,
name,
attributes: {
...opts.attributes,
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'manual',
Expand Down
60 changes: 60 additions & 0 deletions packages/deno/test/opentelemetry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,66 @@ Deno.test('should be compatible with native Deno OpenTelemetry', async () => {
await client.flush();
});

// Test that name parameter takes precedence over options.name for both startSpan and startActiveSpan
Deno.test('name parameter should take precedence over options.name in startSpan', async () => {
resetSdk();
const transactionEvents: any[] = [];

const client = init({
dsn: 'https://username@domain/123',
tracesSampleRate: 1,
beforeSendTransaction: event => {
transactionEvents.push(event);
return null;
},
}) as DenoClient;

const tracer = trace.getTracer('test');

// Pass options with a different name property - the first parameter should take precedence
// This is important for integrations like Prisma that add prefixes to span names
const span = tracer.startSpan('prisma:client:operation', { name: 'operation' } as any);
span.end();

await client.flush();

assertEquals(transactionEvents.length, 1);
const [transactionEvent] = transactionEvents;

// The span name should be 'prisma:client:operation', not 'operation'
assertEquals(transactionEvent?.transaction, 'prisma:client:operation');
});

Deno.test('name parameter should take precedence over options.name in startActiveSpan', async () => {
resetSdk();
const transactionEvents: any[] = [];

const client = init({
dsn: 'https://username@domain/123',
tracesSampleRate: 1,
beforeSendTransaction: event => {
transactionEvents.push(event);
return null;
},
}) as DenoClient;

const tracer = trace.getTracer('test');

// Pass options with a different name property - the first parameter should take precedence
// This is important for integrations like Prisma that add prefixes to span names
tracer.startActiveSpan('prisma:client:operation', { name: 'operation' } as any, span => {
span.end();
});

await client.flush();

assertEquals(transactionEvents.length, 1);
const [transactionEvent] = transactionEvents;

// The span name should be 'prisma:client:operation', not 'operation'
assertEquals(transactionEvent?.transaction, 'prisma:client:operation');
});

Deno.test('should verify native Deno OpenTelemetry works when enabled', async () => {
resetSdk();

Expand Down
Loading