diff --git a/packages/core/src/tracing/dynamicSamplingContext.ts b/packages/core/src/tracing/dynamicSamplingContext.ts index c0298d011568..04510683a1b9 100644 --- a/packages/core/src/tracing/dynamicSamplingContext.ts +++ b/packages/core/src/tracing/dynamicSamplingContext.ts @@ -49,15 +49,15 @@ export function getDynamicSamplingContextFromSpan(span: Span): Readonly = { + const attributes: SpanAttributes = { 'http.method': method, + [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.node.undici', }; if (url.search) { - data['http.query'] = url.search; + attributes['http.query'] = url.search; } if (url.hash) { - data['http.fragment'] = url.hash; + attributes['http.fragment'] = url.hash; } - // eslint-disable-next-line deprecation/deprecation - return activeSpan?.startChild({ + return startInactiveSpan({ + onlyIfParent: true, op: 'http.client', - origin: 'auto.http.node.undici', name: `${method} ${getSanitizedUrlString(url)}`, - data, + attributes, }); } diff --git a/packages/node/test/integrations/http.test.ts b/packages/node/test/integrations/http.test.ts index 62f7aaed1edc..00e642ae6e10 100644 --- a/packages/node/test/integrations/http.test.ts +++ b/packages/node/test/integrations/http.test.ts @@ -1,6 +1,6 @@ import * as http from 'http'; import * as https from 'https'; -import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, getSpanDescendants } from '@sentry/core'; +import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, getSpanDescendants, startSpan } from '@sentry/core'; import type { Hub } from '@sentry/core'; import { getCurrentHub, getIsolationScope, setCurrentClient } from '@sentry/core'; import { Transaction } from '@sentry/core'; @@ -55,7 +55,6 @@ describe('tracing', () => { }); expect(transaction).toBeInstanceOf(Transaction); - // eslint-disable-next-line deprecation/deprecation getCurrentScope().setSpan(transaction); @@ -207,19 +206,20 @@ describe('tracing', () => { const { traceId } = getCurrentScope().getPropagationContext(); - const request = http.get('http://dogs.are.great/'); + // Needs an outer span, or else we skip it + const request = startSpan({ name: 'outer' }, () => http.get('http://dogs.are.great/')); const sentryTraceHeader = request.getHeader('sentry-trace') as string; const baggageHeader = request.getHeader('baggage') as string; const parts = sentryTraceHeader.split('-'); - // Should not include sampling decision since we don't wanna influence the tracing decisions downstream - expect(parts.length).toEqual(2); + expect(parts.length).toEqual(3); expect(parts[0]).toEqual(traceId); expect(parts[1]).toEqual(expect.any(String)); + expect(parts[2]).toEqual('1'); expect(baggageHeader).toEqual( - `sentry-environment=production,sentry-release=1.0.0,sentry-public_key=dogsarebadatkeepingsecrets,sentry-trace_id=${traceId}`, + `sentry-environment=production,sentry-release=1.0.0,sentry-public_key=dogsarebadatkeepingsecrets,sentry-trace_id=${traceId},sentry-sample_rate=1,sentry-transaction=outer,sentry-sampled=true`, ); }); @@ -237,7 +237,8 @@ describe('tracing', () => { }, }); - const request = http.get('http://dogs.are.great/'); + // Needs an outer span, or else we skip it + const request = startSpan({ name: 'outer' }, () => http.get('http://dogs.are.great/')); const sentryTraceHeader = request.getHeader('sentry-trace') as string; const baggageHeader = request.getHeader('baggage') as string;