Skip to content
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
3 changes: 2 additions & 1 deletion packages/core/src/integrations/consola.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { SENTRY_ORIGIN } from '@sentry/conventions/attributes';
import type { Client } from '../client';
import { getClient } from '../currentScopes';
import { _INTERNAL_captureLog } from '../logs/internal';
Expand Down Expand Up @@ -253,7 +254,7 @@ export function createConsolaReporter(options: ConsolaReporterOptions = {}): Con
attributes[key] = normalize(value, normalizeDepth, normalizeMaxBreadth);
}

attributes['sentry.origin'] = 'auto.log.consola';
attributes[SENTRY_ORIGIN] = 'auto.log.consola';

if (tag) {
attributes['consola.tag'] = tag;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
SERVER_PORT,
URL_FULL,
USER_AGENT_ORIGINAL,
HTTP_RESPONSE_STATUS_TEXT,
} from '@sentry/conventions/attributes';
import { HTTP_CLIENT } from '@sentry/conventions/op';

Expand Down Expand Up @@ -77,7 +78,7 @@ export function setIncomingResponseSpanData(response: HttpIncomingMessage, span:
[NETWORK_PROTOCOL_NAME]: 'http',
[NETWORK_PROTOCOL_VERSION]: httpVersion,
[NETWORK_TRANSPORT]: transport,
'http.response.status_text': statusMessage?.toUpperCase(),
[HTTP_RESPONSE_STATUS_TEXT]: statusMessage?.toUpperCase(),
[HTTP_RESPONSE_BODY_SIZE]: getContentLengthFromHeaders(response.headers),
...getSocketAttrs(socket),
});
Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/integrations/http/server-subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ import {
URL_SCHEME,
USER_AGENT_ORIGINAL,
SENTRY_ORIGIN,
HTTP_REQUEST_BODY_SIZE,
HTTP_RESPONSE_STATUS_TEXT,
} from '@sentry/conventions/attributes';
import { HTTP_SERVER } from '@sentry/conventions/op';
import { filterCollectedUrl, filterCollectedUrlQuery } from '../../utils/data-collection/filterCollectedUrl';
Expand Down Expand Up @@ -357,7 +359,7 @@ function buildServerSpanWrap(
[USER_AGENT_ORIGINAL]: userAgent,
[URL_SCHEME]: scheme,
[NETWORK_TRANSPORT]: httpVersion?.toUpperCase() === 'QUIC' ? 'udp' : 'tcp',
'http.request.body.size': getContentLengthFromHeaders(request.headers),
[HTTP_REQUEST_BODY_SIZE]: getContentLengthFromHeaders(request.headers),
...httpHeadersToSpanAttributes(normalizedRequest.headers || {}, dataCollectionOptions),
},
},
Expand All @@ -379,7 +381,7 @@ function buildServerSpanWrap(
isEnded = true;
// set attributes that come from the response
span.setAttributes({
'http.response.status_text': response.statusMessage?.toUpperCase(),
[HTTP_RESPONSE_STATUS_TEXT]: response.statusMessage?.toUpperCase(),
[HTTP_RESPONSE_STATUS_CODE]: response.statusCode,
...httpHeadersToSpanAttributes(headersToDict(response.headers), dataCollectionOptions, 'response'),
});
Expand Down
13 changes: 10 additions & 3 deletions packages/core/src/integrations/requestdata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ import { getUrlQuery } from '../utils/url';
import { getClientIPAddress } from '../utils/clientIPAddress';
import { ipHeaderNames } from '../vendor/getIpAddress';
import { safeSetSpanJSONAttributes } from '../tracing/spans/captureSpan';
import { SENTRY_IS_LOCALHOST, URL_FULL, URL_QUERY, USER_IP_ADDRESS } from '@sentry/conventions/attributes';
import {
SENTRY_IS_LOCALHOST,
URL_FULL,
URL_QUERY,
USER_IP_ADDRESS,
HTTP_REQUEST_BODY_DATA,
HTTP_REQUEST_METHOD,
} from '@sentry/conventions/attributes';

type RequestDataIncludeOptions = {
cookies?: boolean;
Expand Down Expand Up @@ -219,7 +226,7 @@ function addNormalizedRequestDataToSpan(
}

if (requestData.method) {
attributes['http.request.method'] = requestData.method;
attributes[HTTP_REQUEST_METHOD] = requestData.method;
}

if (requestData.query_string) {
Expand Down Expand Up @@ -254,7 +261,7 @@ function addNormalizedRequestDataToSpan(
if (requestData.data != null) {
const serialized = typeof requestData.data === 'string' ? requestData.data : JSON.stringify(requestData.data);
if (serialized) {
safeSetSpanJSONAttributes(span, { 'http.request.body.data': serialized });
safeSetSpanJSONAttributes(span, { [HTTP_REQUEST_BODY_DATA]: serialized });
}
}

Expand Down
33 changes: 23 additions & 10 deletions packages/core/src/logs/internal.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
import {
SENTRY_ENVIRONMENT,
SENTRY_MESSAGE_TEMPLATE,
SENTRY_RELEASE,
SENTRY_REPLAY_ID,
SENTRY_SDK_NAME,
SENTRY_SDK_VERSION,
SENTRY_TRACE_PARENT_SPAN_ID,
USER_EMAIL,
USER_ID,
USER_NAME,
} from '@sentry/conventions/attributes';
import type { Attributes } from '../attributes';
import { serializeAttributes } from '../attributes';
import { getGlobalSingleton } from '../carrier';
Expand Down Expand Up @@ -98,16 +110,16 @@ export function _INTERNAL_captureLog(
attributes: scopeAttributes,
} = getCombinedScopeData(getIsolationScope(), currentScope);

setLogAttribute(processedLogAttributes, 'user.id', id, false);
setLogAttribute(processedLogAttributes, 'user.email', email, false);
setLogAttribute(processedLogAttributes, 'user.name', username, false);
setLogAttribute(processedLogAttributes, USER_ID, id, false);
setLogAttribute(processedLogAttributes, USER_EMAIL, email, false);
setLogAttribute(processedLogAttributes, USER_NAME, username, false);

setLogAttribute(processedLogAttributes, 'sentry.release', release);
setLogAttribute(processedLogAttributes, 'sentry.environment', environment);
setLogAttribute(processedLogAttributes, SENTRY_RELEASE, release);
setLogAttribute(processedLogAttributes, SENTRY_ENVIRONMENT, environment);

const { name, version } = client.getSdkMetadata()?.sdk ?? {};
setLogAttribute(processedLogAttributes, 'sentry.sdk.name', name);
setLogAttribute(processedLogAttributes, 'sentry.sdk.version', version);
setLogAttribute(processedLogAttributes, SENTRY_SDK_NAME, name);
setLogAttribute(processedLogAttributes, SENTRY_SDK_VERSION, version);

const replay = client.getIntegrationByName<
Integration & {
Expand All @@ -117,7 +129,7 @@ export function _INTERNAL_captureLog(
>('Replay');

const replayId = replay?.getReplayId(true);
setLogAttribute(processedLogAttributes, 'sentry.replay_id', replayId);
setLogAttribute(processedLogAttributes, SENTRY_REPLAY_ID, replayId);

if (replayId && replay?.getRecordingMode() === 'buffer') {
// We send this so we can identify cases where the replayId is attached but the replay itself might not have been sent to Sentry
Expand All @@ -128,7 +140,7 @@ export function _INTERNAL_captureLog(
if (isParameterizedString(beforeLogMessage)) {
const { __sentry_template_string__, __sentry_template_values__ = [] } = beforeLogMessage;
if (__sentry_template_values__?.length) {
processedLogAttributes['sentry.message.template'] = __sentry_template_string__;
processedLogAttributes[SENTRY_MESSAGE_TEMPLATE] = __sentry_template_string__;
}
__sentry_template_values__.forEach((param, index) => {
processedLogAttributes[`sentry.message.parameter.${index}`] = param;
Expand All @@ -137,7 +149,8 @@ export function _INTERNAL_captureLog(

const span = getActiveSpan(currentScope);
// Add the parent span ID to the log attributes for trace context
setLogAttribute(processedLogAttributes, 'sentry.trace.parent_span_id', span?.spanContext().spanId);
// oxlint-disable-next-line typescript/no-deprecated -- Preserve the existing attribute name.
setLogAttribute(processedLogAttributes, SENTRY_TRACE_PARENT_SPAN_ID, span?.spanContext().spanId);

const processedLog = { ...beforeLog, attributes: processedLogAttributes };

Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/logs/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { SENTRY_MESSAGE_TEMPLATE } from '@sentry/conventions/attributes';
import { isPrimitive } from '../utils/is';
import { normalize } from '../utils/normalize';
import { GLOBAL_OBJ } from '../utils/worldwide';
Expand Down Expand Up @@ -60,7 +61,7 @@ export function createConsoleTemplateAttributes(firstArg: unknown, followingArgs

// Create template with placeholders for each argument
const template = new Array(followingArgs.length).fill('{}').join(' ');
attributes['sentry.message.template'] = `${firstArg} ${template}`;
attributes[SENTRY_MESSAGE_TEMPLATE] = `${firstArg} ${template}`;

// Add each argument as a parameter
followingArgs.forEach((arg, index) => {
Expand Down
26 changes: 18 additions & 8 deletions packages/core/src/metrics/internal.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
import {
SENTRY_ENVIRONMENT,
SENTRY_RELEASE,
SENTRY_REPLAY_ID,
SENTRY_SDK_NAME,
SENTRY_SDK_VERSION,
USER_EMAIL,
USER_ID,
USER_NAME,
} from '@sentry/conventions/attributes';
import { type RawAttributes, serializeAttributes } from '../attributes';
import { getGlobalSingleton } from '../carrier';
import type { Client } from '../client';
Expand Down Expand Up @@ -88,18 +98,18 @@ function _enrichMetricAttributes(beforeMetric: Metric, client: Client, user: Use
};

// Add user attributes
setMetricAttribute(processedMetricAttributes, 'user.id', user.id, false);
setMetricAttribute(processedMetricAttributes, 'user.email', user.email, false);
setMetricAttribute(processedMetricAttributes, 'user.name', user.username, false);
setMetricAttribute(processedMetricAttributes, USER_ID, user.id, false);
setMetricAttribute(processedMetricAttributes, USER_EMAIL, user.email, false);
setMetricAttribute(processedMetricAttributes, USER_NAME, user.username, false);

// Add Sentry metadata
setMetricAttribute(processedMetricAttributes, 'sentry.release', release);
setMetricAttribute(processedMetricAttributes, 'sentry.environment', environment);
setMetricAttribute(processedMetricAttributes, SENTRY_RELEASE, release);
setMetricAttribute(processedMetricAttributes, SENTRY_ENVIRONMENT, environment);

// Add SDK metadata
const { name, version } = client.getSdkMetadata()?.sdk ?? {};
setMetricAttribute(processedMetricAttributes, 'sentry.sdk.name', name);
setMetricAttribute(processedMetricAttributes, 'sentry.sdk.version', version);
setMetricAttribute(processedMetricAttributes, SENTRY_SDK_NAME, name);
setMetricAttribute(processedMetricAttributes, SENTRY_SDK_VERSION, version);

// Add replay metadata
const replay = client.getIntegrationByName<
Expand All @@ -110,7 +120,7 @@ function _enrichMetricAttributes(beforeMetric: Metric, client: Client, user: Use
>('Replay');

const replayId = replay?.getReplayId(true);
setMetricAttribute(processedMetricAttributes, 'sentry.replay_id', replayId);
setMetricAttribute(processedMetricAttributes, SENTRY_REPLAY_ID, replayId);

if (replayId && replay?.getRecordingMode() === 'buffer') {
setMetricAttribute(processedMetricAttributes, 'sentry._internal.replay_is_buffering', true);
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/server-runtime-client.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { SERVER_ADDRESS } from '@sentry/conventions/attributes';
import { createCheckInEnvelope } from './checkin';
import { Client } from './client';
import { getIsolationScope } from './currentScopes';
Expand Down Expand Up @@ -248,7 +249,7 @@ export class ServerRuntimeClient<
this.on('processMetric', metric => {
if (this._options.serverName) {
metric.attributes = {
'server.address': this._options.serverName,
[SERVER_ADDRESS]: this._options.serverName,
...metric.attributes,
};
}
Expand Down
29 changes: 20 additions & 9 deletions packages/core/src/tracing/spans/scopeContextAttributes.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
import {
ANGULAR_VERSION,
CULTURE_LOCALE,
CULTURE_TIMEZONE,
HTTP_RESPONSE_BODY_SIZE,
HTTP_RESPONSE_STATUS_CODE,
REACT_VERSION,
SENTRY_PROFILER_ID,
SENTRY_PROFILE_ID,
STATE_TYPE,
} from '@sentry/conventions/attributes';
import type { Contexts } from '../../types/context';

/**
Expand All @@ -13,19 +24,19 @@ export function scopeContextsToSpanAttributes(contexts: Contexts): Record<string

if (response) {
if (response.status_code != null) {
attrs['http.response.status_code'] = response.status_code;
attrs[HTTP_RESPONSE_STATUS_CODE] = response.status_code;
}
if (response.body_size != null) {
attrs['http.response.body.size'] = response.body_size;
attrs[HTTP_RESPONSE_BODY_SIZE] = response.body_size;
}
}

if (profile) {
if (profile.profile_id) {
attrs['sentry.profile_id'] = profile.profile_id;
attrs[SENTRY_PROFILE_ID] = profile.profile_id;
}
if (profile.profiler_id) {
attrs['sentry.profiler_id'] = profile.profiler_id;
attrs[SENTRY_PROFILER_ID] = profile.profiler_id;
}
}

Expand All @@ -40,31 +51,31 @@ export function scopeContextsToSpanAttributes(contexts: Contexts): Record<string

if (culture) {
if (culture.locale) {
attrs['culture.locale'] = culture.locale;
attrs[CULTURE_LOCALE] = culture.locale;
}
if (culture.timezone) {
attrs['culture.timezone'] = culture.timezone;
attrs[CULTURE_TIMEZONE] = culture.timezone;
}
}

if (state?.state && typeof state.state.type === 'string') {
attrs['state.type'] = state.state.type;
attrs[STATE_TYPE] = state.state.type;
}

// Framework version contexts
const angular = contexts['angular'];
if (angular) {
const version = angular['version'];
if (typeof version === 'string' || typeof version === 'number') {
attrs['angular.version'] = version;
attrs[ANGULAR_VERSION] = version;
}
}

const react = contexts['react'];
if (react) {
const version = react['version'];
if (typeof version === 'string' || typeof version === 'number') {
attrs['react.version'] = version;
attrs[REACT_VERSION] = version;
}
}

Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/tracing/spanstatus.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { HTTP_RESPONSE_STATUS_CODE } from '@sentry/conventions/attributes';
import type { Span } from '../types/span';
import type { SpanStatusType } from '../types/spanStatus';
import { SPAN_STATUS_TYPES, type SpanStatus } from '../types/spanStatus';
Expand Down Expand Up @@ -64,7 +65,7 @@ export function getSpanStatusFromHttpCode(httpStatus: number): SpanStatus {
* Additionally, the span's status is updated, depending on the http code.
*/
export function setHttpStatus(span: Span, httpStatus: number): void {
span.setAttribute('http.response.status_code', httpStatus);
span.setAttribute(HTTP_RESPONSE_STATUS_CODE, httpStatus);

const spanStatus = getSpanStatusFromHttpCode(httpStatus);
if (spanStatus.message !== 'unknown_error') {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/utils/timestampSequence.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const SEQUENCE_ATTR_KEY = 'sentry.timestamp.sequence';
import { SENTRY_TIMESTAMP_SEQUENCE } from '@sentry/conventions/attributes';

let _sequenceNumber = 0;
let _previousTimestampMs: number | undefined;
Expand Down Expand Up @@ -27,7 +27,7 @@ export function getSequenceAttribute(timestampInSeconds: number): {
_previousTimestampMs = nowMs;

return {
key: SEQUENCE_ATTR_KEY,
key: SENTRY_TIMESTAMP_SEQUENCE,
value: { value, type: 'integer' },
};
}
Expand Down
Loading