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
5 changes: 0 additions & 5 deletions packages/node-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/core": "^1.30.1 || ^2.1.0",
"@opentelemetry/instrumentation": ">=0.57.1 <1",
"@opentelemetry/resources": "^1.30.1 || ^2.1.0",
"@opentelemetry/sdk-trace-base": "^1.30.1 || ^2.1.0",
"@opentelemetry/semantic-conventions": "^1.39.0",
"@opentelemetry/exporter-trace-otlp-http": ">=0.57.0 <1"
Expand All @@ -95,9 +94,6 @@
"@opentelemetry/instrumentation": {
"optional": true
},
"@opentelemetry/resources": {
"optional": true
},
"@opentelemetry/sdk-trace-base": {
"optional": true
},
Expand All @@ -118,7 +114,6 @@
"@opentelemetry/core": "^2.6.1",
"@opentelemetry/exporter-trace-otlp-http": "^0.214.0",
"@opentelemetry/instrumentation": "^0.214.0",
"@opentelemetry/resources": "^2.6.1",
"@opentelemetry/sdk-trace-base": "^2.6.1",
"@opentelemetry/semantic-conventions": "^1.40.0",
"@types/node": "^18.19.1"
Expand Down
18 changes: 2 additions & 16 deletions packages/node-core/test/helpers/mockSdkInit.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { context, propagation, ProxyTracerProvider, trace } from '@opentelemetry/api';
import { defaultResource, resourceFromAttributes } from '@opentelemetry/resources';
import { BasicTracerProvider, type SpanProcessor } from '@opentelemetry/sdk-trace-base';
import {
ATTR_SERVICE_NAME,
ATTR_SERVICE_VERSION,
SEMRESATTRS_SERVICE_NAMESPACE,
} from '@opentelemetry/semantic-conventions';
import {
createTransport,
debug,
Expand All @@ -14,9 +8,8 @@ import {
getGlobalScope,
getIsolationScope,
resolvedSyncPromise,
SDK_VERSION,
} from '@sentry/core';
import { SentryPropagator, SentrySampler, SentrySpanProcessor } from '@sentry/opentelemetry';
import { getSentryResource, SentryPropagator, SentrySampler, SentrySpanProcessor } from '@sentry/opentelemetry';
import type { NodeClient } from '../../src';
import { SentryContextManager, validateOpenTelemetrySetup } from '../../src';
import { init } from '../../src/sdk';
Expand Down Expand Up @@ -64,14 +57,7 @@ export function setupOtel(client: NodeClient): BasicTracerProvider | undefined {
// Create and configure TracerProvider with same config as Node SDK
const provider = new BasicTracerProvider({
sampler: new SentrySampler(client),
resource: defaultResource().merge(
resourceFromAttributes({
[ATTR_SERVICE_NAME]: 'node',
// eslint-disable-next-line deprecation/deprecation
[SEMRESATTRS_SERVICE_NAMESPACE]: 'sentry',
[ATTR_SERVICE_VERSION]: SDK_VERSION,
}),
),
resource: getSentryResource('node'),
forceFlushTimeoutMillis: 500,
spanProcessors: [
new SentrySpanProcessor({
Expand Down
1 change: 0 additions & 1 deletion packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@
"@opentelemetry/instrumentation-redis": "0.62.0",
"@opentelemetry/instrumentation-tedious": "0.33.0",
"@opentelemetry/instrumentation-undici": "0.24.0",
"@opentelemetry/resources": "^2.6.1",
"@opentelemetry/sdk-trace-base": "^2.6.1",
"@opentelemetry/semantic-conventions": "^1.40.0",
"@prisma/instrumentation": "7.6.0",
Expand Down
18 changes: 3 additions & 15 deletions packages/node/src/sdk/initOtel.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import { context, propagation, trace } from '@opentelemetry/api';
import { defaultResource, resourceFromAttributes } from '@opentelemetry/resources';
import type { SpanProcessor } from '@opentelemetry/sdk-trace-base';
import { BasicTracerProvider } from '@opentelemetry/sdk-trace-base';
import {
ATTR_SERVICE_NAME,
ATTR_SERVICE_VERSION,
SEMRESATTRS_SERVICE_NAMESPACE,
} from '@opentelemetry/semantic-conventions';
import { debug as coreDebug, SDK_VERSION } from '@sentry/core';
import { debug as coreDebug } from '@sentry/core';
import {
initializeEsmLoader,
type NodeClient,
Expand All @@ -16,6 +10,7 @@ import {
} from '@sentry/node-core';
import {
type AsyncLocalStorageLookup,
getSentryResource,
SentryPropagator,
SentrySampler,
SentrySpanProcessor,
Expand Down Expand Up @@ -95,14 +90,7 @@ export function setupOtel(
// Create and configure NodeTracerProvider
const provider = new BasicTracerProvider({
sampler: new SentrySampler(client),
resource: defaultResource().merge(
resourceFromAttributes({
[ATTR_SERVICE_NAME]: 'node',
// eslint-disable-next-line deprecation/deprecation
[SEMRESATTRS_SERVICE_NAMESPACE]: 'sentry',
[ATTR_SERVICE_VERSION]: SDK_VERSION,
}),
),
resource: getSentryResource('node'),
forceFlushTimeoutMillis: 500,
spanProcessors: [
new SentrySpanProcessor({
Expand Down
2 changes: 2 additions & 0 deletions packages/opentelemetry/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export { SentrySampler, wrapSamplingDecision } from './sampler';

export { openTelemetrySetupCheck } from './utils/setupCheck';

export { getSentryResource } from './resource';

export { withStreamedSpan } from '@sentry/core';

// Legacy
Expand Down
59 changes: 59 additions & 0 deletions packages/opentelemetry/src/resource.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import type { Attributes, AttributeValue } from '@opentelemetry/api';
import { SDK_INFO } from '@opentelemetry/core';
import {
ATTR_SERVICE_NAME,
ATTR_SERVICE_VERSION,
ATTR_TELEMETRY_SDK_LANGUAGE,
ATTR_TELEMETRY_SDK_NAME,
ATTR_TELEMETRY_SDK_VERSION,
SEMRESATTRS_SERVICE_NAMESPACE,
} from '@opentelemetry/semantic-conventions';
import { SDK_VERSION } from '@sentry/core';

type RawResourceAttribute = [string, AttributeValue | undefined];

/**
* Minimal Resource implementation that satisfies the OpenTelemetry Resource interface
* used by BasicTracerProvider, without depending on `@opentelemetry/resources`.
*/
class SentryResource {
private _attributes: Attributes;

public constructor(attributes: Attributes) {
this._attributes = attributes;
}

public get attributes(): Attributes {
return this._attributes;
}

public merge(other: SentryResource | null): SentryResource {
if (!other) {
return this;
}
return new SentryResource({ ...this._attributes, ...other.attributes });
}

public getRawAttributes(): RawResourceAttribute[] {
return Object.entries(this._attributes);
}
}

/**
* Returns a Resource for use in Sentry's OpenTelemetry TracerProvider setup.
*
* Combines the default OTel SDK telemetry attributes with Sentry-specific
* service attributes, equivalent to what was previously done via:
* `defaultResource().merge(resourceFromAttributes({ ... }))`
*/
export function getSentryResource(serviceName: string): SentryResource {
return new SentryResource({
[ATTR_SERVICE_NAME]: serviceName,
// eslint-disable-next-line deprecation/deprecation
[SEMRESATTRS_SERVICE_NAMESPACE]: 'sentry',
[ATTR_SERVICE_VERSION]: SDK_VERSION,
[ATTR_TELEMETRY_SDK_LANGUAGE]: SDK_INFO[ATTR_TELEMETRY_SDK_LANGUAGE],
[ATTR_TELEMETRY_SDK_NAME]: SDK_INFO[ATTR_TELEMETRY_SDK_NAME],
[ATTR_TELEMETRY_SDK_VERSION]: SDK_INFO[ATTR_TELEMETRY_SDK_VERSION],
});
}
18 changes: 3 additions & 15 deletions packages/opentelemetry/test/helpers/initOtel.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import { context, diag, DiagLogLevel, propagation, trace } from '@opentelemetry/api';
import { defaultResource, resourceFromAttributes } from '@opentelemetry/resources';
import { BasicTracerProvider } from '@opentelemetry/sdk-trace-base';
import {
ATTR_SERVICE_NAME,
ATTR_SERVICE_VERSION,
SEMRESATTRS_SERVICE_NAMESPACE,
} from '@opentelemetry/semantic-conventions';
import { debug, getClient, SDK_VERSION } from '@sentry/core';
import { debug, getClient } from '@sentry/core';
import { SentryAsyncLocalStorageContextManager } from '../../src/asyncLocalStorageContextManager';
import { DEBUG_BUILD } from '../../src/debug-build';
import { SentryPropagator } from '../../src/propagator';
import { getSentryResource } from '../../src/resource';
import { SentrySampler } from '../../src/sampler';
import { setupEventContextTrace } from '../../src/setupEventContextTrace';
import { SentrySpanProcessor } from '../../src/spanProcessor';
Expand Down Expand Up @@ -59,14 +54,7 @@ export function setupOtel(client: TestClientInterface): [BasicTracerProvider, Se
// Create and configure NodeTracerProvider
const provider = new BasicTracerProvider({
sampler: new SentrySampler(client),
resource: defaultResource().merge(
resourceFromAttributes({
[ATTR_SERVICE_NAME]: 'opentelemetry-test',
// eslint-disable-next-line deprecation/deprecation
[SEMRESATTRS_SERVICE_NAMESPACE]: 'sentry',
[ATTR_SERVICE_VERSION]: SDK_VERSION,
}),
),
resource: getSentryResource('opentelemetry-test'),
forceFlushTimeoutMillis: 500,
spanProcessors: [spanProcessor],
});
Expand Down
17 changes: 2 additions & 15 deletions packages/vercel-edge/src/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { context, diag, DiagLogLevel, propagation, trace } from '@opentelemetry/api';
import { defaultResource, resourceFromAttributes } from '@opentelemetry/resources';
import { BasicTracerProvider } from '@opentelemetry/sdk-trace-base';
import {
ATTR_SERVICE_NAME,
ATTR_SERVICE_VERSION,
SEMRESATTRS_SERVICE_NAMESPACE,
} from '@opentelemetry/semantic-conventions';
import type { Client, Integration, Options } from '@sentry/core';
import {
consoleIntegration,
Expand All @@ -22,12 +16,12 @@ import {
linkedErrorsIntegration,
nodeStackLineParser,
requestDataIntegration,
SDK_VERSION,
Comment thread
mydea marked this conversation as resolved.
spanStreamingIntegration,
stackParserFromStackParserOptions,
} from '@sentry/core';
import {
enhanceDscWithOpenTelemetryRootSpanName,
getSentryResource,
openTelemetrySetupCheck,
SentryPropagator,
SentrySampler,
Expand Down Expand Up @@ -166,14 +160,7 @@ export function setupOtel(client: VercelEdgeClient): void {
// Create and configure NodeTracerProvider
const provider = new BasicTracerProvider({
sampler: new SentrySampler(client),
resource: defaultResource().merge(
resourceFromAttributes({
[ATTR_SERVICE_NAME]: 'edge',
// eslint-disable-next-line deprecation/deprecation
[SEMRESATTRS_SERVICE_NAMESPACE]: 'sentry',
[ATTR_SERVICE_VERSION]: SDK_VERSION,
}),
),
resource: getSentryResource('edge'),
forceFlushTimeoutMillis: 500,
spanProcessors: [
new SentrySpanProcessor({
Expand Down
Loading