Skip to content

Commit 7a6698c

Browse files
committed
use new attribute serialization for spanv2
1 parent ceb8407 commit 7a6698c

File tree

5 files changed

+14
-113
lines changed

5 files changed

+14
-113
lines changed

packages/core/src/attributes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export type RawAttributes<T> = T & ValidatedAttributes<T>;
66
// eslint-disable-next-line @typescript-eslint/no-explicit-any
77
export type RawAttribute<T> = T extends { value: any } | { unit: any } ? AttributeObject : T;
88

9-
export type Attributes = Record<string, TypedAttributeValue>;
9+
export type TypedAttributes = Record<string, TypedAttributeValue>;
1010

1111
export type AttributeValueType = string | number | boolean | Array<string> | Array<number> | Array<boolean>;
1212

packages/core/src/spans/spanFirstUtils.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import type { RawAttributes } from '../attributes';
2-
import { isAttributeObject } from '../attributes';
2+
import { attributeValueToTypedAttributeValue, isAttributeObject } from '../attributes';
33
import type { Context, Contexts } from '../types-hoist/context';
44
import type { SpanV2JSON } from '../types-hoist/span';
5-
import { attributeValueToSerializedAttribute } from '../utils/attributes';
65
import { isPrimitive } from '../utils/is';
76
import { showSpanDropWarning } from '../utils/spanUtils';
87

@@ -56,13 +55,13 @@ function setAttributeOnSpanJSONWithMaybeUnit(
5655
const { value, unit } = attributeValue;
5756

5857
if (isSupportedSerializableType(value)) {
59-
spanJSON.attributes[attributeKey] = attributeValueToSerializedAttribute(value);
58+
spanJSON.attributes[attributeKey] = attributeValueToTypedAttributeValue(attributeValue);
6059
if (unit) {
6160
spanJSON.attributes[attributeKey].unit = unit;
6261
}
6362
}
6463
} else if (isSupportedSerializableType(attributeValue)) {
65-
spanJSON.attributes[attributeKey] = attributeValueToSerializedAttribute(attributeValue);
64+
spanJSON.attributes[attributeKey] = attributeValueToTypedAttributeValue(attributeValue);
6665
}
6766
}
6867

@@ -118,8 +117,8 @@ const knownContexts = [
118117
'state',
119118
// set by `replayIntegration`
120119
'Replays',
121-
// set by feature flags integration(s)
122-
'flags',
120+
// Other information:
121+
// - no need to handler feature flags `flags` context because it's already added to the active span
123122
];
124123

125124
/**

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { SerializedAttributes } from './attributes';
1+
import type { TypedAttributes } from '../attributes';
22
import type { SpanLink, SpanLinkJSON } from './link';
33
import type { Measurements } from './measurement';
44
import type { HrTime } from './opentelemetry';
@@ -47,8 +47,8 @@ export interface SpanV2JSON {
4747
end_timestamp: number;
4848
status: 'ok' | 'error';
4949
is_segment: boolean;
50-
attributes?: SerializedAttributes;
51-
links?: SpanLinkJSON<SerializedAttributes>[];
50+
attributes?: TypedAttributes;
51+
links?: SpanLinkJSON<TypedAttributes>[];
5252
}
5353

5454
/**

packages/core/src/utils/spanUtils.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { getAsyncContextStrategy } from '../asyncContext';
2+
import { attributeValueToTypedAttributeValue, TypedAttributes } from '../attributes';
23
import { getMainCarrier } from '../carrier';
34
import { getCurrentScope } from '../currentScopes';
45
import {
@@ -111,7 +112,7 @@ export function convertSpanLinksForEnvelope(links?: SpanLink[]): SpanLinkJSON[]
111112
* @param links
112113
* @returns
113114
*/
114-
export function getV2SpanLinks(links?: SpanLink[]): SpanLinkJSON<SerializedAttributes>[] | undefined {
115+
export function getV2SpanLinks(links?: SpanLink[]): SpanLinkJSON<TypedAttributes>[] | undefined {
115116
if (links?.length) {
116117
return links.map(({ context: { spanId, traceId, traceFlags, ...restContext }, attributes }) => ({
117118
span_id: spanId,
@@ -320,11 +321,11 @@ export function getV2StatusMessage(status: SpanStatus | undefined): 'ok' | 'erro
320321
/**
321322
* Convert the attributes to the ones expected by Sentry, including the type annotation
322323
*/
323-
export function getV2Attributes(attributes: SpanAttributes): SerializedAttributes {
324+
export function getV2Attributes(attributes: SpanAttributes): TypedAttributes {
324325
return Object.entries(attributes).reduce((acc, [key, value]) => {
325-
acc[key] = attributeValueToSerializedAttribute(value);
326+
acc[key] = attributeValueToTypedAttributeValue(value);
326327
return acc;
327-
}, {} as SerializedAttributes);
328+
}, {} as TypedAttributes);
328329
}
329330

330331
const CHILD_SPANS_FIELD = '_sentryChildSpans';

packages/core/test/lib/utils/attributes.test.ts

Lines changed: 0 additions & 99 deletions
This file was deleted.

0 commit comments

Comments
 (0)