Skip to content

ref(opentelemetry): Use debug instead of logger #16990

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 15, 2025
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
6 changes: 5 additions & 1 deletion packages/node-core/test/integration/transactions.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { context, trace, TraceFlags } from '@opentelemetry/api';
import type { SpanProcessor } from '@opentelemetry/sdk-trace-base';
import type { TransactionEvent } from '@sentry/core';
import { logger, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';
import { debug, logger, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';
import { SentrySpanProcessor } from '@sentry/opentelemetry';
import { afterEach, describe, expect, it, vi } from 'vitest';
import * as Sentry from '../../src';
Expand Down Expand Up @@ -558,7 +558,9 @@ describe('Integration | Transactions', () => {
vi.setSystemTime(now);

const logs: unknown[] = [];
// TODO: Remove this once node is using debug instead of logger
vi.spyOn(logger, 'log').mockImplementation(msg => logs.push(msg));
vi.spyOn(debug, 'log').mockImplementation(msg => logs.push(msg));

mockSdkInit({ tracesSampleRate: 1, beforeSendTransaction });

Expand Down Expand Up @@ -636,7 +638,9 @@ describe('Integration | Transactions', () => {
vi.setSystemTime(now);

const logs: unknown[] = [];
// TODO: Remove this once node is using debug instead of logger
vi.spyOn(logger, 'log').mockImplementation(msg => logs.push(msg));
vi.spyOn(debug, 'log').mockImplementation(msg => logs.push(msg));

mockSdkInit({
tracesSampleRate: 1,
Expand Down
6 changes: 5 additions & 1 deletion packages/node/test/integration/transactions.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { context, trace, TraceFlags } from '@opentelemetry/api';
import type { SpanProcessor } from '@opentelemetry/sdk-trace-base';
import type { TransactionEvent } from '@sentry/core';
import { logger, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';
import { debug, logger, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';
import { SentrySpanProcessor } from '@sentry/opentelemetry';
import { afterEach, describe, expect, it, vi } from 'vitest';
import * as Sentry from '../../src';
Expand Down Expand Up @@ -558,7 +558,9 @@ describe('Integration | Transactions', () => {
vi.setSystemTime(now);

const logs: unknown[] = [];
// TODO: Remove this once node is using debug instead of logger
vi.spyOn(logger, 'log').mockImplementation(msg => logs.push(msg));
vi.spyOn(debug, 'log').mockImplementation(msg => logs.push(msg));

mockSdkInit({ tracesSampleRate: 1, beforeSendTransaction });

Expand Down Expand Up @@ -636,7 +638,9 @@ describe('Integration | Transactions', () => {
vi.setSystemTime(now);

const logs: unknown[] = [];
// TODO: Remove this once node is using debug instead of logger
vi.spyOn(logger, 'log').mockImplementation(msg => logs.push(msg));
vi.spyOn(debug, 'log').mockImplementation(msg => logs.push(msg));

mockSdkInit({
tracesSampleRate: 1,
Expand Down
13 changes: 5 additions & 8 deletions packages/opentelemetry/src/propagator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { isTracingSuppressed, W3CBaggagePropagator } from '@opentelemetry/core';
import { ATTR_URL_FULL, SEMATTRS_HTTP_URL } from '@opentelemetry/semantic-conventions';
import type { Client, continueTrace, DynamicSamplingContext, Options, Scope } from '@sentry/core';
import {
debug,
generateSentryTraceHeader,
getClient,
getCurrentScope,
getDynamicSamplingContextFromScope,
getDynamicSamplingContextFromSpan,
getIsolationScope,
logger,
LRUMap,
parseBaggageHeader,
propagationContextFromHeaders,
Expand Down Expand Up @@ -45,7 +45,7 @@ export class SentryPropagator extends W3CBaggagePropagator {
*/
public inject(context: Context, carrier: unknown, setter: TextMapSetter): void {
if (isTracingSuppressed(context)) {
DEBUG_BUILD && logger.log('[Tracing] Not injecting trace data for url because tracing is suppressed.');
DEBUG_BUILD && debug.log('[Tracing] Not injecting trace data for url because tracing is suppressed.');
return;
}

Expand All @@ -55,10 +55,7 @@ export class SentryPropagator extends W3CBaggagePropagator {
const tracePropagationTargets = getClient()?.getOptions()?.tracePropagationTargets;
if (!shouldPropagateTraceForUrl(url, tracePropagationTargets, this._urlMatchesTargetsMap)) {
DEBUG_BUILD &&
logger.log(
'[Tracing] Not injecting trace data for url because it does not match tracePropagationTargets:',
url,
);
debug.log('[Tracing] Not injecting trace data for url because it does not match tracePropagationTargets:', url);
return;
}

Expand Down Expand Up @@ -139,14 +136,14 @@ export function shouldPropagateTraceForUrl(

const cachedDecision = decisionMap?.get(url);
if (cachedDecision !== undefined) {
DEBUG_BUILD && !cachedDecision && logger.log(NOT_PROPAGATED_MESSAGE, url);
DEBUG_BUILD && !cachedDecision && debug.log(NOT_PROPAGATED_MESSAGE, url);
return cachedDecision;
}

const decision = stringMatchesSomePattern(url, tracePropagationTargets);
decisionMap?.set(url, decision);

DEBUG_BUILD && !decision && logger.log(NOT_PROPAGATED_MESSAGE, url);
DEBUG_BUILD && !decision && debug.log(NOT_PROPAGATED_MESSAGE, url);
return decision;
}

Expand Down
10 changes: 5 additions & 5 deletions packages/opentelemetry/src/sampler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {
import type { Client, SpanAttributes } from '@sentry/core';
import {
baggageHeaderToDynamicSamplingContext,
debug,
hasSpansEnabled,
logger,
parseSampleRate,
sampleSpan,
SEMANTIC_ATTRIBUTE_SENTRY_OP,
Expand Down Expand Up @@ -137,7 +137,7 @@ export class SentrySampler implements Sampler {

const method = `${maybeSpanHttpMethod}`.toUpperCase();
if (method === 'OPTIONS' || method === 'HEAD') {
DEBUG_BUILD && logger.log(`[Tracing] Not sampling span because HTTP method is '${method}' for ${spanName}`);
DEBUG_BUILD && debug.log(`[Tracing] Not sampling span because HTTP method is '${method}' for ${spanName}`);

return wrapSamplingDecision({
decision: SamplingDecision.NOT_RECORD,
Expand All @@ -153,7 +153,7 @@ export class SentrySampler implements Sampler {
// We check for `parentSampled === undefined` because we only want to record client reports for spans that are trace roots (ie. when there was incoming trace)
parentSampled === undefined
) {
DEBUG_BUILD && logger.log('[Tracing] Discarding root span because its trace was not chosen to be sampled.');
DEBUG_BUILD && debug.log('[Tracing] Discarding root span because its trace was not chosen to be sampled.');
this._client.recordDroppedEvent('sample_rate', 'transaction');
}

Expand Down Expand Up @@ -187,12 +187,12 @@ function getParentSampled(parentSpan: Span, traceId: string, spanName: string):
if (parentContext.isRemote) {
const parentSampled = getSamplingDecision(parentSpan.spanContext());
DEBUG_BUILD &&
logger.log(`[Tracing] Inheriting remote parent's sampled decision for ${spanName}: ${parentSampled}`);
debug.log(`[Tracing] Inheriting remote parent's sampled decision for ${spanName}: ${parentSampled}`);
return parentSampled;
}

const parentSampled = getSamplingDecision(parentContext);
DEBUG_BUILD && logger.log(`[Tracing] Inheriting parent's sampled decision for ${spanName}: ${parentSampled}`);
DEBUG_BUILD && debug.log(`[Tracing] Inheriting parent's sampled decision for ${spanName}: ${parentSampled}`);
return parentSampled;
}

Expand Down
6 changes: 3 additions & 3 deletions packages/opentelemetry/src/spanExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import {
captureEvent,
convertSpanLinksForEnvelope,
debounce,
debug,
getCapturedScopesOnSpan,
getDynamicSamplingContextFromSpan,
getStatusMessage,
logger,
SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME,
SEMANTIC_ATTRIBUTE_SENTRY_OP,
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
Expand Down Expand Up @@ -105,7 +105,7 @@ export class SentrySpanExporter {
});
if (droppedSpanCount > 0) {
DEBUG_BUILD &&
logger.log(
debug.log(
`SpanExporter dropped ${droppedSpanCount} spans because they were pending for more than ${this._finishedSpanBucketSize} seconds.`,
);
}
Expand Down Expand Up @@ -142,7 +142,7 @@ export class SentrySpanExporter {
const sentSpanCount = sentSpans.size;
const remainingOpenSpanCount = finishedSpans.length - sentSpanCount;
DEBUG_BUILD &&
logger.log(
debug.log(
`SpanExporter exported ${sentSpanCount} spans, ${remainingOpenSpanCount} spans are waiting for their parent spans to finish`,
);

Expand Down
22 changes: 13 additions & 9 deletions packages/opentelemetry/test/helpers/initOtel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
ATTR_SERVICE_VERSION,
SEMRESATTRS_SERVICE_NAMESPACE,
} from '@opentelemetry/semantic-conventions';
import { getClient, logger, SDK_VERSION } from '@sentry/core';
import { debug, getClient, SDK_VERSION } from '@sentry/core';
import { wrapContextManagerClass } from '../../src/contextManager';
import { DEBUG_BUILD } from '../../src/debug-build';
import { SentryPropagator } from '../../src/propagator';
Expand All @@ -25,21 +25,25 @@ export function initOtel(): void {

if (!client) {
DEBUG_BUILD &&
logger.warn(
debug.warn(
'No client available, skipping OpenTelemetry setup. This probably means that `Sentry.init()` was not called before `initOtel()`.',
);
return;
}

if (client.getOptions().debug) {
const otelLogger = new Proxy(logger as typeof logger & { verbose: (typeof logger)['debug'] }, {
get(target, prop, receiver) {
const actualProp = prop === 'verbose' ? 'debug' : prop;
return Reflect.get(target, actualProp, receiver);
// Disable diag, to ensure this works even if called multiple times
diag.disable();
Comment on lines +35 to +36
Copy link
Member

Choose a reason for hiding this comment

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

I don't fully get this one 😬

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 copied this from another implementation, I think it makes sense to keep (so we align).

diag.setLogger(
{
error: debug.error,
warn: debug.warn,
info: debug.log,
debug: debug.log,
verbose: debug.log,
},
});

diag.setLogger(otelLogger, DiagLogLevel.DEBUG);
DiagLogLevel.DEBUG,
);
}

setupEventContextTrace(client);
Expand Down
12 changes: 6 additions & 6 deletions packages/opentelemetry/test/integration/transactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import type { SpanProcessor } from '@opentelemetry/sdk-trace-base';
import type { Event, TransactionEvent } from '@sentry/core';
import {
addBreadcrumb,
debug,
getClient,
logger,
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
setTag,
Expand Down Expand Up @@ -440,7 +440,7 @@ describe('Integration | Transactions', () => {
vi.setSystemTime(now);

const logs: unknown[] = [];
vi.spyOn(logger, 'log').mockImplementation(msg => logs.push(msg));
vi.spyOn(debug, 'log').mockImplementation(msg => logs.push(msg));

mockSdkInit({ tracesSampleRate: 1, beforeSendTransaction });

Expand Down Expand Up @@ -510,7 +510,7 @@ describe('Integration | Transactions', () => {
vi.setSystemTime(now);

const logs: unknown[] = [];
vi.spyOn(logger, 'log').mockImplementation(msg => logs.push(msg));
vi.spyOn(debug, 'log').mockImplementation(msg => logs.push(msg));

const transactions: Event[] = [];

Expand Down Expand Up @@ -568,7 +568,7 @@ describe('Integration | Transactions', () => {
vi.setSystemTime(now);

const logs: unknown[] = [];
vi.spyOn(logger, 'log').mockImplementation(msg => logs.push(msg));
vi.spyOn(debug, 'log').mockImplementation(msg => logs.push(msg));

const transactions: Event[] = [];

Expand Down Expand Up @@ -625,7 +625,7 @@ describe('Integration | Transactions', () => {
vi.setSystemTime(now);

const logs: unknown[] = [];
vi.spyOn(logger, 'log').mockImplementation(msg => logs.push(msg));
vi.spyOn(debug, 'log').mockImplementation(msg => logs.push(msg));

const transactions: Event[] = [];

Expand Down Expand Up @@ -687,7 +687,7 @@ describe('Integration | Transactions', () => {
vi.setSystemTime(now);

const logs: unknown[] = [];
vi.spyOn(logger, 'log').mockImplementation(msg => logs.push(msg));
vi.spyOn(debug, 'log').mockImplementation(msg => logs.push(msg));

const transactions: Event[] = [];

Expand Down
Loading