Skip to content

Commit f87b5ba

Browse files
committed
remove is_remote, add is_segment
1 parent 243b8ae commit f87b5ba

File tree

5 files changed

+11
-50
lines changed

5 files changed

+11
-50
lines changed

packages/browser/src/integrations/spanstreaming.ts

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import type { Client, IntegrationFn, Scope, ScopeData, Span, SpanAttributes, SpanV2JSON } from '@sentry/core';
22
import {
3-
attributesFromObject,
43
createSpanV2Envelope,
54
debug,
65
defineIntegration,
76
getCapturedScopesOnSpan,
87
getDynamicSamplingContextFromSpan,
98
getGlobalScope,
10-
getRootSpan as getSegmentSpan,
11-
httpHeadersToSpanAttributes,
9+
INTERNAL_getSegmentSpan,
1210
isV2BeforeSendSpanCallback,
1311
mergeScopeData,
1412
reparentChildSpans,
@@ -18,7 +16,6 @@ import {
1816
SEMANTIC_ATTRIBUTE_SENTRY_SDK_NAME,
1917
SEMANTIC_ATTRIBUTE_SENTRY_SDK_VERSION,
2018
SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_NAME,
21-
SEMANTIC_ATTRIBUTE_URL_FULL,
2219
SEMANTIC_ATTRIBUTE_USER_EMAIL,
2320
SEMANTIC_ATTRIBUTE_USER_ID,
2421
SEMANTIC_ATTRIBUTE_USER_IP_ADDRESS,
@@ -28,7 +25,6 @@ import {
2825
spanToV2JSON,
2926
} from '@sentry/core';
3027
import { DEBUG_BUILD } from '../debug-build';
31-
import { getHttpRequestData } from '../helpers';
3228

3329
export interface SpanStreamingOptions {
3430
batchLimit: number;
@@ -110,7 +106,7 @@ interface SpanProcessingOptions {
110106
* Just the traceid alone isn't enough because there can be multiple span trees with the same traceid.
111107
*/
112108
function getSpanTreeMapKey(span: Span): string {
113-
return `${span.spanContext().traceId}-${getSegmentSpan(span).spanContext().spanId}`;
109+
return `${span.spanContext().traceId}-${INTERNAL_getSegmentSpan(span).spanContext().spanId}`;
114110
}
115111

116112
function processAndSendSpans(
@@ -132,10 +128,6 @@ function processAndSendSpans(
132128
applyCommonSpanAttributes(span, segmentSpanJson, client);
133129
}
134130

135-
applyScopeToSegmentSpan(segmentSpan, segmentSpanJson, client);
136-
137-
// TODO: Apply scope data and contexts to segment span
138-
139131
const { ignoreSpans } = client.getOptions();
140132

141133
// 1. Check if the entire span tree is ignored by ignoreSpans
@@ -166,6 +158,7 @@ function processAndSendSpans(
166158
}
167159

168160
// 3. Apply beforeSendSpan callback
161+
// TODO: validate beforeSendSpan result/pass in a copy and merge afterwards
169162
const processedSpan = beforeSendSpan ? applyBeforeSendSpanCallback(span, beforeSendSpan) : span;
170163
processedSpans.push(processedSpan);
171164
}
@@ -224,38 +217,6 @@ function applyCommonSpanAttributes(span: Span, serializedSegmentSpan: SpanV2JSON
224217
});
225218
}
226219

227-
/**
228-
* Adds span attributes from the scopes' contexts
229-
* TODO: It's not set in stone yet if we actually want to flatmap contexts into span attributes.
230-
* For now we do it but not yet extra or tags. It's still TBD how to proceed here.
231-
*/
232-
function applyScopeToSegmentSpan(segmentSpan: Span, serializedSegmentSpan: SpanV2JSON, client: Client): void {
233-
const { isolationScope, scope } = getCapturedScopesOnSpan(segmentSpan);
234-
const finalScopeData = getFinalScopeData(isolationScope, scope);
235-
236-
const browserRequestData = getHttpRequestData();
237-
238-
const tags = finalScopeData.tags ?? {};
239-
240-
let contextAttributes = {};
241-
Object.keys(finalScopeData.contexts).forEach(key => {
242-
const context = finalScopeData.contexts[key];
243-
if (context) {
244-
contextAttributes = { ...contextAttributes, ...attributesFromObject(context) };
245-
}
246-
});
247-
248-
const extraAttributes = attributesFromObject(finalScopeData.extra);
249-
250-
setAttributesIfNotPresent(segmentSpan, Object.keys(serializedSegmentSpan.attributes ?? {}), {
251-
[SEMANTIC_ATTRIBUTE_URL_FULL]: browserRequestData.url,
252-
...httpHeadersToSpanAttributes(browserRequestData.headers, client.getOptions().sendDefaultPii ?? false),
253-
...tags,
254-
...contextAttributes,
255-
...extraAttributes,
256-
});
257-
}
258-
259220
function applyBeforeSendSpanCallback(span: SpanV2JSON, beforeSendSpan: (span: SpanV2JSON) => SpanV2JSON): SpanV2JSON {
260221
const modifedSpan = beforeSendSpan(span);
261222
if (!modifedSpan) {

packages/core/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export {
7676
getSpanDescendants,
7777
getStatusMessage,
7878
getRootSpan,
79-
getSegmentSpan,
79+
INTERNAL_getSegmentSpan,
8080
getActiveSpan,
8181
addChildSpanToSpan,
8282
spanTimeInputToSeconds,

packages/core/src/tracing/sentrySpan.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ export class SentrySpan implements Span {
263263
start_timestamp: this._startTime,
264264
// just in case _endTime is not set, we use the start time (i.e. duration 0)
265265
end_timestamp: this._endTime ?? this._startTime,
266-
is_remote: false, // TODO: This has to be inferred from attributes SentrySpans. `false` is the default.
266+
is_segment: this._isStandaloneSpan || this === getRootSpan(this),
267267
kind: 'internal', // TODO: This has to be inferred from attributes SentrySpans. `internal` is the default.
268268
status: getV2StatusMessage(this._status),
269269
attributes: getV2Attributes(this._attributes),

packages/core/src/types-hoist/span.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export interface SpanV2JSON {
4444
end_timestamp: number;
4545
status: 'ok' | 'error';
4646
kind: 'server' | 'client' | 'internal' | 'consumer' | 'producer';
47-
is_remote: boolean;
47+
is_segment: boolean;
4848
attributes?: SerializedAttributes;
4949
links?: SpanLinkJSON<SerializedAttributes>[];
5050
}

packages/core/src/utils/spanUtils.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ export function spanToV2JSON(span: Span): SpanV2JSON {
216216
return span.getSpanV2JSON();
217217
}
218218

219-
const { spanId: span_id, traceId: trace_id, isRemote } = span.spanContext();
219+
const { spanId: span_id, traceId: trace_id } = span.spanContext();
220220

221221
// Handle a span from @opentelemetry/sdk-base-trace's `Span` class
222222
if (spanIsOpenTelemetrySdkTraceBaseSpan(span)) {
@@ -240,7 +240,7 @@ export function spanToV2JSON(span: Span): SpanV2JSON {
240240
parent_span_id: parentSpanId,
241241
start_timestamp: spanTimeInputToSeconds(startTime),
242242
end_timestamp: spanTimeInputToSeconds(endTime),
243-
is_remote: isRemote || false,
243+
is_segment: span === INTERNAL_getSegmentSpan(span),
244244
kind: 'internal', // TODO: Figure out how to get this from the OTel span as it's not publicly exposed
245245
status: getV2StatusMessage(status),
246246
attributes: getV2Attributes(attributes),
@@ -258,7 +258,7 @@ export function spanToV2JSON(span: Span): SpanV2JSON {
258258
end_timestamp: 0,
259259
status: 'ok',
260260
kind: 'internal',
261-
is_remote: isRemote || false,
261+
is_segment: span === INTERNAL_getSegmentSpan(span),
262262
};
263263
}
264264

@@ -394,12 +394,12 @@ export function getSpanDescendants(span: SpanWithPotentialChildren): Span[] {
394394
/**
395395
* Returns the root span of a given span.
396396
*/
397-
export const getRootSpan = getSegmentSpan;
397+
export const getRootSpan = INTERNAL_getSegmentSpan;
398398

399399
/**
400400
* Returns the segment span of a given span.
401401
*/
402-
export function getSegmentSpan(span: SpanWithPotentialChildren): Span {
402+
export function INTERNAL_getSegmentSpan(span: SpanWithPotentialChildren): Span {
403403
return span[ROOT_SPAN_FIELD] || span;
404404
}
405405

0 commit comments

Comments
 (0)