Skip to content

feat(node): Ensure manual OTEL setup works #12214

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
May 27, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const NODE_EXPORTS_IGNORE = [
'setNodeAsyncContextStrategy',
'getDefaultIntegrationsWithoutPerformance',
'initWithoutDefaultIntegrations',
'SentryContextManager',
'validateOpenTelemetrySetup',
];

const nodeExports = Object.keys(SentryNode).filter(e => !NODE_EXPORTS_IGNORE.includes(e));
Expand Down
2 changes: 2 additions & 0 deletions packages/node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ export { koaIntegration, setupKoaErrorHandler } from './integrations/tracing/koa
export { connectIntegration, setupConnectErrorHandler } from './integrations/tracing/connect';
export { spotlightIntegration } from './integrations/spotlight';

export { SentryContextManager } from './otel/contextManager';
export {
init,
getDefaultIntegrations,
getDefaultIntegrationsWithoutPerformance,
initWithoutDefaultIntegrations,
validateOpenTelemetrySetup,
} from './sdk/init';
export { initOpenTelemetry } from './sdk/initOtel';
export { getAutoPerformanceIntegrations } from './integrations/tracing';
Expand Down
14 changes: 11 additions & 3 deletions packages/node/src/sdk/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import {
requestDataIntegration,
startSession,
} from '@sentry/core';
import { openTelemetrySetupCheck, setOpenTelemetryContextAsyncContextStrategy } from '@sentry/opentelemetry';
import {
openTelemetrySetupCheck,
setOpenTelemetryContextAsyncContextStrategy,
setupEventContextTrace,
} from '@sentry/opentelemetry';
import type { Client, Integration, Options } from '@sentry/types';
import {
GLOBAL_OBJ,
Expand Down Expand Up @@ -196,12 +200,16 @@ function _init(
// There is no way to use this SDK without OpenTelemetry!
if (!options.skipOpenTelemetrySetup) {
initOpenTelemetry(client);
validateOpenTelemetrySetup();
}

validateOpenTelemetrySetup();
setupEventContextTrace(client);
}

function validateOpenTelemetrySetup(): void {
/**
* Validate that your OpenTelemetry setup is correct.
*/
export function validateOpenTelemetrySetup(): void {
if (!DEBUG_BUILD) {
return;
}
Expand Down
4 changes: 1 addition & 3 deletions packages/node/src/sdk/initOtel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
SEMRESATTRS_SERVICE_VERSION,
} from '@opentelemetry/semantic-conventions';
import { SDK_VERSION } from '@sentry/core';
import { SentryPropagator, SentrySampler, SentrySpanProcessor, setupEventContextTrace } from '@sentry/opentelemetry';
import { SentryPropagator, SentrySampler, SentrySpanProcessor } from '@sentry/opentelemetry';
import { logger } from '@sentry/utils';

import { SentryContextManager } from '../otel/contextManager';
Expand All @@ -28,8 +28,6 @@ export function initOpenTelemetry(client: NodeClient): void {
diag.setLogger(otelLogger, DiagLogLevel.DEBUG);
}

setupEventContextTrace(client);

const provider = setupOtel(client);
client.traceProvider = provider;
}
Expand Down
Loading