Skip to content

Commit 70f92af

Browse files
committed
feat(deno): Add OTeL compatability tests, move vercelai to /tracing
1 parent f93232a commit 70f92af

File tree

4 files changed

+83
-9
lines changed

4 files changed

+83
-9
lines changed

packages/deno/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"lint:es-compatibility": "es-check es2022 ./build/esm/*.js --module",
4444
"install:deno": "node ./scripts/install-deno.mjs",
4545
"test": "run-s install:deno deno-types test:unit",
46-
"test:unit": "deno test --allow-read --allow-run --no-check",
46+
"test:unit": "deno test --allow-read --allow-run --allow-env --no-check",
4747
"test:unit:update": "deno test --allow-read --allow-write --allow-run -- --update",
4848
"yalc:publish": "yalc publish --push --sig"
4949
},

packages/deno/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,4 @@ export { normalizePathsIntegration } from './integrations/normalizepaths';
101101
export { contextLinesIntegration } from './integrations/contextlines';
102102
export { denoCronIntegration } from './integrations/deno-cron';
103103
export { breadcrumbsIntegration } from './integrations/breadcrumbs';
104-
export { vercelAIIntegration } from './integrations/vercelai';
104+
export { vercelAIIntegration } from './integrations/tracing/vercelai';

packages/deno/src/integrations/vercelai.ts renamed to packages/deno/src/integrations/tracing/vercelai.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
/**
22
* This is a copy of the Vercel AI integration from the cloudflare SDK.
3-
*
4-
* The only difference is that it does not use `@opentelemetry/instrumentation`
5-
* because Deno Workers do not support it in the same way.
6-
*
7-
* Therefore, we cannot automatically patch setting `experimental_telemetry: { isEnabled: true }`
8-
* and users have to manually set this to get spans.
93
*/
104

115
import type { IntegrationFn } from '@sentry/core';

packages/deno/test/opentelemetry.test.ts

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { assertEquals } from 'https://deno.land/[email protected]/assert/mod.ts';
1+
import { assertEquals, assertNotEquals } from 'https://deno.land/[email protected]/assert/mod.ts';
22
import { context, propagation, trace } from 'npm:@opentelemetry/api@1';
33
import type { DenoClient } from '../build/esm/index.js';
44
import { getCurrentScope, getGlobalScope, getIsolationScope, init, startSpan } from '../build/esm/index.js';
@@ -143,3 +143,83 @@ Deno.test('opentelemetry spans should interop with Sentry spans', async () => {
143143
assertEquals(otelSpan?.data?.['sentry.deno_tracer'], true);
144144
assertEquals(otelSpan?.data?.['sentry.origin'], 'manual');
145145
});
146+
147+
Deno.test('should be compatible with native Deno OpenTelemetry', async () => {
148+
resetSdk();
149+
150+
const providerBefore = trace.getTracerProvider();
151+
152+
const client = init({
153+
dsn: 'https://username@domain/123',
154+
tracesSampleRate: 1,
155+
beforeSendTransaction: () => null,
156+
}) as DenoClient;
157+
158+
const providerAfter = trace.getTracerProvider();
159+
assertEquals(providerBefore, providerAfter);
160+
161+
const tracer = trace.getTracer('compat-test');
162+
const span = tracer.startSpan('test-span');
163+
span.setAttributes({ 'test.compatibility': true });
164+
span.end();
165+
166+
tracer.startActiveSpan('active-span', (activeSpan) => {
167+
activeSpan.end();
168+
});
169+
170+
const otelSpan = tracer.startSpan('post-init-span');
171+
otelSpan.end();
172+
173+
startSpan({ name: 'sentry-span' }, () => {
174+
const nestedOtelSpan = tracer.startSpan('nested-otel-span');
175+
nestedOtelSpan.end();
176+
});
177+
178+
await client.flush();
179+
});
180+
181+
Deno.test('should verify native Deno OpenTelemetry works when enabled', async () => {
182+
resetSdk();
183+
184+
// Set environment variable to enable native OTel
185+
const originalValue = Deno.env.get('OTEL_DENO');
186+
Deno.env.set('OTEL_DENO', 'true');
187+
188+
try {
189+
const client = init({
190+
dsn: 'https://username@domain/123',
191+
tracesSampleRate: 1,
192+
beforeSendTransaction: () => null,
193+
}) as DenoClient;
194+
195+
const provider = trace.getTracerProvider();
196+
const tracer = trace.getTracer('native-verification');
197+
const span = tracer.startSpan('verification-span');
198+
199+
if (provider.constructor.name === 'Function') {
200+
// Native OTel is active
201+
assertNotEquals(span.constructor.name, 'NonRecordingSpan');
202+
203+
let contextWorks = false;
204+
tracer.startActiveSpan('parent-span', (parentSpan) => {
205+
if (trace.getActiveSpan() === parentSpan) {
206+
contextWorks = true;
207+
}
208+
parentSpan.end();
209+
});
210+
assertEquals(contextWorks, true);
211+
}
212+
213+
span.setAttributes({ 'test.native_otel': true });
214+
span.end();
215+
216+
await client.flush();
217+
} finally {
218+
// Restore original environment
219+
if (originalValue === undefined) {
220+
Deno.env.delete('OTEL_DENO');
221+
} else {
222+
Deno.env.set('OTEL_DENO', originalValue);
223+
}
224+
}
225+
});

0 commit comments

Comments
 (0)