Skip to content

feat(opentelemetry): Do not use SentrySpan & Transaction classes #10982

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 3 commits into from
Mar 8, 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
2 changes: 2 additions & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export {
spanIsSampled,
spanToTraceContext,
getSpanDescendants,
getStatusMessage,
} from './utils/spanUtils';
export { getRootSpan } from './utils/getRootSpan';
export { applySdkMetadata } from './utils/sdkMetadata';
Expand All @@ -114,4 +115,5 @@ export { metrics } from './metrics/exports';
export type { MetricData } from './metrics/exports';
export { metricsDefault } from './metrics/exports-default';
export { BrowserMetricsAggregator } from './metrics/browser-aggregator';
export { getMetricSummaryJsonForSpan } from './metrics/metric-summary';
export { addTracingHeadersToFetchRequest, instrumentFetchRequest } from './fetch';
157 changes: 77 additions & 80 deletions packages/node-experimental/test/integration/transactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,17 @@ describe('Integration | Transactions', () => {
});

it('correctly creates transaction & spans', async () => {
const beforeSendTransaction = jest.fn(() => null);
const transactions: TransactionEvent[] = [];
const beforeSendTransaction = jest.fn(event => {
transactions.push(event);
return null;
});

mockSdkInit({ enableTracing: true, beforeSendTransaction });
mockSdkInit({
enableTracing: true,
beforeSendTransaction,
release: '8.0.0',
});

const client = Sentry.getClient()!;

Expand Down Expand Up @@ -58,86 +66,75 @@ describe('Integration | Transactions', () => {

await client.flush();

expect(beforeSendTransaction).toHaveBeenCalledTimes(1);
expect(beforeSendTransaction).toHaveBeenLastCalledWith(
expect.objectContaining({
breadcrumbs: [
{ message: 'test breadcrumb 1', timestamp: 123456 },
{ message: 'test breadcrumb 2', timestamp: 123456 },
{ message: 'test breadcrumb 3', timestamp: 123456 },
],
contexts: {
otel: {
attributes: {
'test.outer': 'test value',
'sentry.op': 'test op',
'sentry.origin': 'auto.test',
'sentry.source': 'task',
},
resource: {
'service.name': 'node',
'service.namespace': 'sentry',
'service.version': expect.any(String),
'telemetry.sdk.language': 'nodejs',
'telemetry.sdk.name': 'opentelemetry',
'telemetry.sdk.version': expect.any(String),
},
},
runtime: { name: 'node', version: expect.any(String) },
trace: {
data: {
'otel.kind': 'INTERNAL',
'sentry.op': 'test op',
'sentry.origin': 'auto.test',
'sentry.source': 'task',
'sentry.sample_rate': 1,
'test.outer': 'test value',
},
op: 'test op',
span_id: expect.any(String),
status: 'ok',
trace_id: expect.any(String),
origin: 'auto.test',
},
},
environment: 'production',
event_id: expect.any(String),
platform: 'node',
sdkProcessingMetadata: expect.objectContaining({
dynamicSamplingContext: expect.objectContaining({
environment: 'production',
public_key: expect.any(String),
sample_rate: '1',
sampled: 'true',
trace_id: expect.any(String),
transaction: 'test name',
}),
sampleRate: 1,
spanMetadata: expect.any(Object),
requestPath: 'test-path',
}),
server_name: expect.any(String),
// spans are circular (they have a reference to the transaction), which leads to jest choking on this
// instead we compare them in detail below
spans: [expect.any(Object), expect.any(Object)],
start_timestamp: expect.any(Number),
tags: {
'outer.tag': 'test value',
'test.tag': 'test value',
},
timestamp: expect.any(Number),
transaction: 'test name',
transaction_info: { source: 'task' },
type: 'transaction',
}),
{
event_id: expect.any(String),
expect(transactions).toHaveLength(1);
const transaction = transactions[0];

expect(transaction.breadcrumbs).toEqual([
{ message: 'test breadcrumb 1', timestamp: 123456 },
{ message: 'test breadcrumb 2', timestamp: 123456 },
{ message: 'test breadcrumb 3', timestamp: 123456 },
]);

expect(transaction.contexts?.otel).toEqual({
attributes: {
'test.outer': 'test value',
'sentry.op': 'test op',
'sentry.origin': 'auto.test',
'sentry.source': 'task',
},
);
resource: {
'service.name': 'node',
'service.namespace': 'sentry',
'service.version': expect.any(String),
'telemetry.sdk.language': 'nodejs',
'telemetry.sdk.name': 'opentelemetry',
'telemetry.sdk.version': expect.any(String),
},
});

// Checking the spans here, as they are circular to the transaction...
const runArgs = beforeSendTransaction.mock.calls[0] as unknown as [TransactionEvent, unknown];
const spans = runArgs[0].spans || [];
expect(transaction.contexts?.trace).toEqual({
data: {
'otel.kind': 'INTERNAL',
'sentry.op': 'test op',
'sentry.origin': 'auto.test',
'sentry.source': 'task',
'sentry.sample_rate': 1,
'test.outer': 'test value',
},
op: 'test op',
span_id: expect.any(String),
status: 'ok',
trace_id: expect.any(String),
origin: 'auto.test',
});

expect(transaction.sdkProcessingMetadata?.sampleRate).toEqual(1);
expect(transaction.sdkProcessingMetadata?.requestPath).toEqual('test-path');
expect(transaction.sdkProcessingMetadata?.dynamicSamplingContext).toEqual({
environment: 'production',
public_key: expect.any(String),
sample_rate: '1',
sampled: 'true',
release: '8.0.0',
trace_id: expect.any(String),
transaction: 'test name',
});

expect(transaction.environment).toEqual('production');
expect(transaction.event_id).toEqual(expect.any(String));
expect(transaction.start_timestamp).toEqual(expect.any(Number));
expect(transaction.timestamp).toEqual(expect.any(Number));
expect(transaction.transaction).toEqual('test name');

expect(transaction.tags).toEqual({
'outer.tag': 'test value',
'test.tag': 'test value',
});
expect(transaction.transaction_info).toEqual({ source: 'task' });
expect(transaction.type).toEqual('transaction');

expect(transaction.spans).toHaveLength(2);
const spans = transaction.spans || [];

// note: Currently, spans do not have any context/span added to them
// This is the same behavior as for the "regular" SDKs
Expand Down
33 changes: 0 additions & 33 deletions packages/opentelemetry/src/custom/hubextensions.ts

This file was deleted.

21 changes: 0 additions & 21 deletions packages/opentelemetry/src/custom/transaction.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/opentelemetry/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export { startSpan, startSpanManual, startInactiveSpan, withActiveSpan } from '.
export { setupGlobalHub } from './custom/hub';
// eslint-disable-next-line deprecation/deprecation
export { getCurrentHub } from './custom/getCurrentHub';
export { addTracingExtensions } from './custom/hubextensions';
export { setupEventContextTrace } from './setupEventContextTrace';

export { setOpenTelemetryContextAsyncContextStrategy } from './asyncContextStrategy';
Expand Down
Loading