Skip to content

Commit c67db15

Browse files
committed
split into two methods
1 parent 09e176b commit c67db15

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

packages/core/src/server-runtime-client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ export class ServerRuntimeClient<
257257
if (span) {
258258
const rootSpan = getRootSpan(span);
259259
const samplingContext = getDynamicSamplingContextFromSpan(rootSpan);
260-
return [samplingContext, spanToTraceContext(rootSpan, false)];
260+
return [samplingContext, spanToTraceContext(rootSpan)];
261261
}
262262

263263
const { traceId, spanId, parentSpanId, dsc } = scope.getPropagationContext();

packages/core/src/tracing/sentrySpan.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {
3232
getStatusMessage,
3333
spanTimeInputToSeconds,
3434
spanToJSON,
35-
spanToTraceContext,
35+
spanToTransactionTraceContext,
3636
} from '../utils/spanUtils';
3737
import { getDynamicSamplingContextFromSpan } from './dynamicSamplingContext';
3838
import { logSpanEnd } from './logSpans';
@@ -275,7 +275,7 @@ export class SentrySpan implements Span {
275275

276276
const transaction: TransactionEvent = {
277277
contexts: {
278-
trace: spanToTraceContext(this, true),
278+
trace: spanToTransactionTraceContext(this),
279279
},
280280
spans,
281281
start_timestamp: this._startTime,

packages/core/src/utils/applyScopeDataToEvent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ function applySdkMetadataToEvent(event: Event, sdkProcessingMetadata: ScopeData[
162162

163163
function applySpanToEvent(event: Event, span: Span): void {
164164
event.contexts = {
165-
trace: spanToTraceContext(span, false),
165+
trace: spanToTraceContext(span),
166166
...event.contexts,
167167
};
168168

packages/core/src/utils/spanUtils.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,29 @@ export const TRACE_FLAG_SAMPLED = 0x1;
3434
* By default, this will only include trace_id, span_id & parent_span_id.
3535
* If `includeAllData` is true, it will also include data, op, status & origin.
3636
*/
37-
export function spanToTraceContext(span: Span, includeAllData = false): TraceContext {
37+
export function spanToTransactionTraceContext(span: Span): TraceContext {
3838
const { spanId: span_id, traceId: trace_id } = span.spanContext();
3939
const { data, op, parent_span_id, status, origin } = spanToJSON(span);
4040

41-
const reqFields = { parent_span_id, span_id, trace_id };
42-
// These are only included if `includeAllData` is true
43-
const optFields = { data, op, status, origin };
41+
return dropUndefinedKeys({
42+
parent_span_id,
43+
span_id,
44+
trace_id,
45+
data,
46+
op,
47+
status,
48+
origin,
49+
});
50+
}
51+
52+
/**
53+
* Convert a span to a trace context, which can be sent as the `trace` context in a non-transaction event.
54+
*/
55+
export function spanToTraceContext(span: Span): TraceContext {
56+
const { spanId: span_id, traceId: trace_id } = span.spanContext();
57+
const { parent_span_id } = spanToJSON(span);
4458

45-
return dropUndefinedKeys(includeAllData ? { ...reqFields, ...optFields } : reqFields);
59+
return dropUndefinedKeys({ parent_span_id, span_id, trace_id });
4660
}
4761

4862
/**

0 commit comments

Comments
 (0)