Skip to content

ref(vercel-edge): Use debug in vercel edge sdk #16912

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 14, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
21 changes: 15 additions & 6 deletions packages/vercel-edge/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { Client, Integration, Options } from '@sentry/core';
import {
consoleIntegration,
createStackParser,
debug,
dedupeIntegration,
functionToStringIntegration,
getCurrentScope,
Expand All @@ -18,7 +19,6 @@ import {
hasSpansEnabled,
inboundFiltersIntegration,
linkedErrorsIntegration,
logger,
nodeStackLineParser,
requestDataIntegration,
SDK_VERSION,
Expand Down Expand Up @@ -135,14 +135,14 @@ function validateOpenTelemetrySetup(): void {

for (const k of required) {
if (!setup.includes(k)) {
logger.error(
debug.error(
`You have to set up the ${k}. Without this, the OpenTelemetry & Sentry integration will not work properly.`,
);
}
}

if (!setup.includes('SentrySampler')) {
logger.warn(
debug.warn(
'You have to set up the SentrySampler. Without this, the OpenTelemetry & Sentry integration may still work, but sample rates set for the Sentry SDK will not be respected. If you use a custom sampler, make sure to use `wrapSamplingDecision`.',
);
}
Expand Down Expand Up @@ -182,10 +182,10 @@ export function setupOtel(client: VercelEdgeClient): void {
}

/**
* Setup the OTEL logger to use our own logger.
* Setup the OTEL logger to use our own debug logger.
*/
function setupOpenTelemetryLogger(): void {
const otelLogger = new Proxy(logger as typeof logger & { verbose: (typeof logger)['debug'] }, {
const otelLogger = new Proxy(debug as typeof debug & { verbose: (typeof debug)['log'] }, {
Copy link
Member

Choose a reason for hiding this comment

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

hmm do we even need this? Can we not directly set e.g. { error: debug.error, warn: debug.warn, ... } then here?

Copy link
Member

Choose a reason for hiding this comment

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

(which imho is much nicer than the proxy anyhow)

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree, will make the change! I just blindly copied the pattern (just assumed it was there for some reason I couldn't understand 😄)

get(target, prop, receiver) {
const actualProp = prop === 'verbose' ? 'debug' : prop;
return Reflect.get(target, actualProp, receiver);
Expand All @@ -194,7 +194,16 @@ function setupOpenTelemetryLogger(): void {

// Disable diag, to ensure this works even if called multiple times
diag.disable();
diag.setLogger(otelLogger, DiagLogLevel.DEBUG);
diag.setLogger(
{
error: otelLogger.error,
warn: otelLogger.warn,
info: otelLogger.log,
debug: otelLogger.log,
verbose: otelLogger.log,
},
DiagLogLevel.DEBUG,
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

import type { Context } from '@opentelemetry/api';
import { ROOT_CONTEXT } from '@opentelemetry/api';
import { GLOBAL_OBJ, logger } from '@sentry/core';
import { debug, GLOBAL_OBJ } from '@sentry/core';
import type { AsyncLocalStorage } from 'async_hooks';
import { DEBUG_BUILD } from '../debug-build';
import { AbstractAsyncHooksContextManager } from './abstract-async-hooks-context-manager';
Expand All @@ -42,7 +42,7 @@ export class AsyncLocalStorageContextManager extends AbstractAsyncHooksContextMa

if (!MaybeGlobalAsyncLocalStorageConstructor) {
DEBUG_BUILD &&
logger.warn(
debug.warn(
"Tried to register AsyncLocalStorage async context strategy in a runtime that doesn't support AsyncLocalStorage.",
);

Expand Down
Loading