@sentry/opentelemetry 10.58.0 → 10.60.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  import * as api from '@opentelemetry/api';
2
2
  import { trace, SpanKind, createContextKey, TraceFlags, propagation, INVALID_TRACEID, context, SpanStatusCode, ROOT_CONTEXT, isSpanContextValid } from '@opentelemetry/api';
3
- import { parseUrl, getSanitizedUrlString, SDK_VERSION, derefWeakRef, addNonEnumerableProperty, makeWeakRef, isSentryRequestUrl, getClient, baggageHeaderToDynamicSamplingContext, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME, stripUrlQueryAndFragment, spanToJSON, hasSpansEnabled, dynamicSamplingContextToSentryBaggageHeader, LRUMap, debug, shouldPropagateTraceForUrl, parseBaggageHeader, SENTRY_BAGGAGE_KEY_PREFIX, generateSentryTraceHeader, generateTraceparentHeader, getDynamicSamplingContextFromSpan, getCurrentScope, getDynamicSamplingContextFromScope, getIsolationScope, propagationContextFromHeaders, shouldContinueTrace, spanToTraceContext, getTraceContextFromScope, generateTraceId, generateSpanId, _INTERNAL_safeMathRandom, getRootSpan, handleCallbackErrors, getCapturedScopesOnSpan, setAsyncContextStrategy, getDefaultIsolationScope, getDefaultCurrentScope, SPAN_STATUS_OK, SPAN_STATUS_ERROR, getSpanStatusFromHttpCode, _INTERNAL_safeDateNow, debounce, timedEventsToMeasurements, captureEvent, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, convertSpanLinksForEnvelope, getStatusMessage, spanTimeInputToSeconds, addChildSpanToSpan, setCapturedScopesOnSpan, logSpanStart, logSpanEnd, hasSpanStreamingEnabled, shouldIgnoreSpan, parseSampleRate, sampleSpan } from '@sentry/core';
4
- import { ATTR_URL_FULL, SEMATTRS_HTTP_URL, ATTR_HTTP_REQUEST_METHOD, SEMATTRS_HTTP_METHOD, ATTR_DB_SYSTEM_NAME, SEMATTRS_DB_SYSTEM, SEMATTRS_RPC_SERVICE, SEMATTRS_MESSAGING_SYSTEM, SEMATTRS_FAAS_TRIGGER, SEMATTRS_DB_STATEMENT, SEMATTRS_HTTP_TARGET, ATTR_HTTP_ROUTE, ATTR_HTTP_RESPONSE_STATUS_CODE, SEMATTRS_HTTP_STATUS_CODE, SEMATTRS_RPC_GRPC_STATUS_CODE, ATTR_TELEMETRY_SDK_VERSION, ATTR_TELEMETRY_SDK_NAME, ATTR_TELEMETRY_SDK_LANGUAGE, ATTR_SERVICE_VERSION, ATTR_SERVICE_NAME, SEMRESATTRS_SERVICE_NAMESPACE } from '@opentelemetry/semantic-conventions';
3
+ import { parseUrl, getSanitizedUrlString, SDK_VERSION, derefWeakRef, addNonEnumerableProperty, makeWeakRef, isSentryRequestUrl, getClient, baggageHeaderToDynamicSamplingContext, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME, stripUrlQueryAndFragment, spanToJSON, hasSpansEnabled, dynamicSamplingContextToSentryBaggageHeader, LRUMap, debug, shouldPropagateTraceForUrl, parseBaggageHeader, SENTRY_BAGGAGE_KEY_PREFIX, generateSentryTraceHeader, generateTraceparentHeader, getDynamicSamplingContextFromSpan, getCurrentScope, getDynamicSamplingContextFromScope, getIsolationScope, propagationContextFromHeaders, shouldContinueTrace, spanToTraceContext, getTraceContextFromScope, generateTraceId, generateSpanId, _INTERNAL_safeMathRandom, getRootSpan, handleCallbackErrors, getCapturedScopesOnSpan, setAsyncContextStrategy, getDefaultIsolationScope, getDefaultCurrentScope, SPAN_STATUS_OK, SPAN_STATUS_ERROR, getSpanStatusFromHttpCode, _INTERNAL_safeDateNow, debounce, timedEventsToMeasurements, captureEvent, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, convertSpanLinksForEnvelope, getStatusMessage, spanTimeInputToSeconds, hasSpanStreamingEnabled, addChildSpanToSpan, setCapturedScopesOnSpan, logSpanStart, logSpanEnd, safeSetSpanJSONAttributes, shouldIgnoreSpan, parseSampleRate, sampleSpan } from '@sentry/core';
4
+ import { URL_FULL, HTTP_URL, HTTP_REQUEST_METHOD, HTTP_METHOD, DB_SYSTEM_NAME, DB_SYSTEM, RPC_SERVICE, MESSAGING_SYSTEM, FAAS_TRIGGER, DB_STATEMENT, HTTP_TARGET, HTTP_ROUTE, HTTP_RESPONSE_STATUS_CODE, HTTP_STATUS_CODE, RPC_GRPC_STATUS_CODE, SERVICE_VERSION, SERVICE_NAME } from '@sentry/conventions/attributes';
5
5
  import { W3CBaggagePropagator, isTracingSuppressed, suppressTracing as suppressTracing$1, SDK_INFO } from '@opentelemetry/core';
6
6
  import { D as DEBUG_BUILD } from './debug-build-B98wrZ1j.js';
7
7
  import { SamplingDecision } from '@opentelemetry/sdk-trace-base';
@@ -47,11 +47,11 @@ function getRequestSpanData(span) {
47
47
  if (!spanHasAttributes(span)) {
48
48
  return {};
49
49
  }
50
- const maybeUrlAttribute = span.attributes[ATTR_URL_FULL] || span.attributes[SEMATTRS_HTTP_URL];
50
+ const maybeUrlAttribute = span.attributes[URL_FULL] || span.attributes[HTTP_URL];
51
51
  const data = {
52
52
  url: maybeUrlAttribute,
53
- // eslint-disable-next-line deprecation/deprecation
54
- "http.method": span.attributes[ATTR_HTTP_REQUEST_METHOD] || span.attributes[SEMATTRS_HTTP_METHOD]
53
+ // eslint-disable-next-line typescript/no-deprecated
54
+ "http.method": span.attributes[HTTP_REQUEST_METHOD] || span.attributes[HTTP_METHOD]
55
55
  };
56
56
  if (!data["http.method"] && data.url) {
57
57
  data["http.method"] = "GET";
@@ -140,7 +140,7 @@ function isSentryRequestSpan(span) {
140
140
  return false;
141
141
  }
142
142
  const { attributes } = span;
143
- const httpUrl = attributes[SEMATTRS_HTTP_URL] || attributes[ATTR_URL_FULL];
143
+ const httpUrl = attributes[HTTP_URL] || attributes[URL_FULL];
144
144
  if (!httpUrl) {
145
145
  return false;
146
146
  }
@@ -168,31 +168,31 @@ function getSamplingDecision(spanContext) {
168
168
  }
169
169
 
170
170
  function inferSpanData(spanName, attributes, kind) {
171
- const httpMethod = attributes[ATTR_HTTP_REQUEST_METHOD] || attributes[SEMATTRS_HTTP_METHOD];
171
+ const httpMethod = attributes[HTTP_REQUEST_METHOD] || attributes[HTTP_METHOD];
172
172
  if (httpMethod) {
173
173
  return descriptionForHttpMethod({ attributes, name: spanName, kind }, httpMethod);
174
174
  }
175
- const dbSystem = attributes[ATTR_DB_SYSTEM_NAME] || attributes[SEMATTRS_DB_SYSTEM];
175
+ const dbSystem = attributes[DB_SYSTEM_NAME] || attributes[DB_SYSTEM];
176
176
  const opIsCache = typeof attributes[SEMANTIC_ATTRIBUTE_SENTRY_OP] === "string" && attributes[SEMANTIC_ATTRIBUTE_SENTRY_OP].startsWith("cache.");
177
177
  if (dbSystem && !opIsCache) {
178
178
  return descriptionForDbSystem({ attributes, name: spanName });
179
179
  }
180
180
  const customSourceOrRoute = attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] === "custom" ? "custom" : "route";
181
- const rpcService = attributes[SEMATTRS_RPC_SERVICE];
181
+ const rpcService = attributes[RPC_SERVICE];
182
182
  if (rpcService) {
183
183
  return {
184
184
  ...getUserUpdatedNameAndSource(spanName, attributes, "route"),
185
185
  op: "rpc"
186
186
  };
187
187
  }
188
- const messagingSystem = attributes[SEMATTRS_MESSAGING_SYSTEM];
188
+ const messagingSystem = attributes[MESSAGING_SYSTEM];
189
189
  if (messagingSystem) {
190
190
  return {
191
191
  ...getUserUpdatedNameAndSource(spanName, attributes, customSourceOrRoute),
192
192
  op: "message"
193
193
  };
194
194
  }
195
- const faasTrigger = attributes[SEMATTRS_FAAS_TRIGGER];
195
+ const faasTrigger = attributes[FAAS_TRIGGER];
196
196
  if (faasTrigger) {
197
197
  return {
198
198
  ...getUserUpdatedNameAndSource(spanName, attributes, customSourceOrRoute),
@@ -219,7 +219,7 @@ function descriptionForDbSystem({ attributes, name }) {
219
219
  if (attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] === "custom") {
220
220
  return { op: "db", description: name, source: "custom" };
221
221
  }
222
- const statement = attributes[SEMATTRS_DB_STATEMENT];
222
+ const statement = attributes[DB_STATEMENT];
223
223
  const description = statement ? statement.toString() : name;
224
224
  return { op: "db", description, source: "task" };
225
225
  }
@@ -280,9 +280,9 @@ function getGraphqlOperationNamesFromAttribute(attr) {
280
280
  return `${attr}`;
281
281
  }
282
282
  function getSanitizedUrl(attributes, kind) {
283
- const httpTarget = attributes[SEMATTRS_HTTP_TARGET];
284
- const httpUrl = attributes[SEMATTRS_HTTP_URL] || attributes[ATTR_URL_FULL];
285
- const httpRoute = attributes[ATTR_HTTP_ROUTE];
283
+ const httpTarget = attributes[HTTP_TARGET];
284
+ const httpUrl = attributes[HTTP_URL] || attributes[URL_FULL];
285
+ const httpRoute = attributes[HTTP_ROUTE];
286
286
  const parsedUrl = typeof httpUrl === "string" ? parseUrl(httpUrl) : void 0;
287
287
  const url = parsedUrl ? getSanitizedUrlString(parsedUrl) : void 0;
288
288
  const query = parsedUrl?.search || void 0;
@@ -538,7 +538,7 @@ function getExistingSentryTrace(carrier) {
538
538
  }
539
539
  function getCurrentURL(span) {
540
540
  const spanData = spanToJSON(span).data;
541
- const urlAttribute = spanData[SEMATTRS_HTTP_URL] || spanData[ATTR_URL_FULL];
541
+ const urlAttribute = spanData[HTTP_URL] || spanData[URL_FULL];
542
542
  if (typeof urlAttribute === "string") {
543
543
  return urlAttribute;
544
544
  }
@@ -1000,8 +1000,8 @@ function mapStatus(span) {
1000
1000
  }
1001
1001
  }
1002
1002
  function inferStatusFromAttributes(attributes) {
1003
- const httpCodeAttribute = attributes[ATTR_HTTP_RESPONSE_STATUS_CODE] || attributes[SEMATTRS_HTTP_STATUS_CODE];
1004
- const grpcCodeAttribute = attributes[SEMATTRS_RPC_GRPC_STATUS_CODE];
1003
+ const httpCodeAttribute = attributes[HTTP_RESPONSE_STATUS_CODE] || attributes[HTTP_STATUS_CODE];
1004
+ const grpcCodeAttribute = attributes[RPC_GRPC_STATUS_CODE];
1005
1005
  const numberHttpCode = typeof httpCodeAttribute === "number" ? httpCodeAttribute : typeof httpCodeAttribute === "string" ? parseInt(httpCodeAttribute) : void 0;
1006
1006
  if (typeof numberHttpCode === "number") {
1007
1007
  return getSpanStatusFromHttpCode(numberHttpCode);
@@ -1177,7 +1177,7 @@ function createTransactionForOtelSpan(span) {
1177
1177
  // As per protocol, span status is allowed to be undefined
1178
1178
  links: convertSpanLinksForEnvelope(links)
1179
1179
  };
1180
- const statusCode = attributes[ATTR_HTTP_RESPONSE_STATUS_CODE];
1180
+ const statusCode = attributes[HTTP_RESPONSE_STATUS_CODE];
1181
1181
  const responseContext = typeof statusCode === "number" ? { response: { status_code: statusCode } } : void 0;
1182
1182
  const transactionEvent = {
1183
1183
  contexts: {
@@ -1285,9 +1285,9 @@ function getData(span) {
1285
1285
  if (span.kind !== SpanKind.INTERNAL) {
1286
1286
  data["otel.kind"] = SpanKind[span.kind];
1287
1287
  }
1288
- const maybeHttpStatusCodeAttribute = attributes[SEMATTRS_HTTP_STATUS_CODE];
1288
+ const maybeHttpStatusCodeAttribute = attributes[HTTP_STATUS_CODE];
1289
1289
  if (maybeHttpStatusCodeAttribute) {
1290
- data[ATTR_HTTP_RESPONSE_STATUS_CODE] = maybeHttpStatusCodeAttribute;
1290
+ data[HTTP_RESPONSE_STATUS_CODE] = maybeHttpStatusCodeAttribute;
1291
1291
  }
1292
1292
  const requestData = getRequestSpanData(span);
1293
1293
  if (requestData.url) {
@@ -1304,8 +1304,13 @@ function getData(span) {
1304
1304
 
1305
1305
  class SentrySpanProcessor {
1306
1306
  constructor(options) {
1307
+ this._unsubscribePreprocessSpan = void 0;
1307
1308
  setIsSetup("SentrySpanProcessor");
1308
1309
  this._exporter = new SentrySpanExporter(options);
1310
+ this._client = options?.client ?? getClient();
1311
+ if (this._client && hasSpanStreamingEnabled(this._client)) {
1312
+ this._unsubscribePreprocessSpan = this._client.on("preprocessSpan", backfillStreamedSpanDataFromOtel);
1313
+ }
1309
1314
  }
1310
1315
  /**
1311
1316
  * @inheritDoc
@@ -1317,6 +1322,7 @@ class SentrySpanProcessor {
1317
1322
  * @inheritDoc
1318
1323
  */
1319
1324
  async shutdown() {
1325
+ this._unsubscribePreprocessSpan?.();
1320
1326
  this._exporter.clear();
1321
1327
  }
1322
1328
  /**
@@ -1341,21 +1347,38 @@ class SentrySpanProcessor {
1341
1347
  setCapturedScopesOnSpan(span, scopes.scope, scopes.isolationScope);
1342
1348
  }
1343
1349
  logSpanStart(span);
1344
- const client = getClient();
1345
- client?.emit("spanStart", span);
1350
+ this._client?.emit("spanStart", span);
1346
1351
  }
1347
1352
  /** @inheritDoc */
1348
1353
  onEnd(span) {
1349
1354
  logSpanEnd(span);
1350
- const client = getClient();
1351
- client?.emit("spanEnd", span);
1352
- if (client && hasSpanStreamingEnabled(client)) {
1353
- client.emit("afterSpanEnd", span);
1355
+ this._client?.emit("spanEnd", span);
1356
+ if (this._client && hasSpanStreamingEnabled(this._client)) {
1357
+ this._client.emit("afterSpanEnd", span);
1354
1358
  } else {
1355
1359
  this._exporter.export(span);
1356
1360
  }
1357
1361
  }
1358
1362
  }
1363
+ function backfillStreamedSpanDataFromOtel(spanJSON, hint) {
1364
+ const attributes = spanJSON.attributes;
1365
+ if (!attributes) {
1366
+ return;
1367
+ }
1368
+ const kind = hint?.spanKind ?? SpanKind.INTERNAL;
1369
+ const { op, description, source, data } = inferSpanData(spanJSON.name, attributes, kind);
1370
+ spanJSON.name = description;
1371
+ safeSetSpanJSONAttributes(spanJSON, {
1372
+ [SEMANTIC_ATTRIBUTE_SENTRY_OP]: op,
1373
+ [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source,
1374
+ ...data
1375
+ });
1376
+ if (kind !== SpanKind.INTERNAL) {
1377
+ safeSetSpanJSONAttributes(spanJSON, {
1378
+ "otel.kind": SpanKind[kind]
1379
+ });
1380
+ }
1381
+ }
1359
1382
 
1360
1383
  class SentrySampler {
1361
1384
  constructor(client) {
@@ -1372,7 +1395,7 @@ class SentrySampler {
1372
1395
  if (!hasSpansEnabled(options)) {
1373
1396
  return wrapSamplingDecision({ decision: void 0, context, spanAttributes });
1374
1397
  }
1375
- const maybeSpanHttpMethod = spanAttributes[SEMATTRS_HTTP_METHOD] || spanAttributes[ATTR_HTTP_REQUEST_METHOD];
1398
+ const maybeSpanHttpMethod = spanAttributes[HTTP_METHOD] || spanAttributes[HTTP_REQUEST_METHOD];
1376
1399
  if (spanKind === SpanKind.CLIENT && maybeSpanHttpMethod && (!parentSpan || parentContext?.isRemote)) {
1377
1400
  if (!this._isSpanStreaming) {
1378
1401
  this._client.recordDroppedEvent("no_parent_span", "span");
@@ -1556,7 +1579,7 @@ function getBaseTraceState(context, spanAttributes) {
1556
1579
  const parentSpan = trace.getSpan(context);
1557
1580
  const parentContext = parentSpan?.spanContext();
1558
1581
  let traceState = parentContext?.traceState || new TraceState();
1559
- const url = spanAttributes[SEMATTRS_HTTP_URL] || spanAttributes[ATTR_URL_FULL];
1582
+ const url = spanAttributes[HTTP_URL] || spanAttributes[URL_FULL];
1560
1583
  if (url && typeof url === "string") {
1561
1584
  traceState = traceState.set(SENTRY_TRACE_STATE_URL, url);
1562
1585
  }
@@ -1567,6 +1590,10 @@ function getValidSpan(context) {
1567
1590
  return span && isSpanContextValid(span.spanContext()) ? span : void 0;
1568
1591
  }
1569
1592
 
1593
+ const ATTR_TELEMETRY_SDK_LANGUAGE = "telemetry.sdk.language";
1594
+ const ATTR_TELEMETRY_SDK_NAME = "telemetry.sdk.name";
1595
+ const ATTR_TELEMETRY_SDK_VERSION = "telemetry.sdk.version";
1596
+ const SEMRESATTRS_SERVICE_NAMESPACE = "service.namespace";
1570
1597
  class SentryResource {
1571
1598
  constructor(attributes) {
1572
1599
  this._attributes = attributes;
@@ -1612,15 +1639,15 @@ function getSentryResource(serviceNameFallback) {
1612
1639
  const otelResourceAttrs = parseOtelResourceAttributes(env.OTEL_RESOURCE_ATTRIBUTES);
1613
1640
  return new SentryResource({
1614
1641
  // Lowest priority: Sentry defaults
1615
- // eslint-disable-next-line deprecation/deprecation
1642
+ // eslint-disable-next-line typescript/no-deprecated
1616
1643
  [SEMRESATTRS_SERVICE_NAMESPACE]: "sentry",
1617
- [ATTR_SERVICE_NAME]: serviceNameFallback,
1644
+ [SERVICE_NAME]: serviceNameFallback,
1618
1645
  // OTEL_RESOURCE_ATTRIBUTES overrides defaults (including service.name and service.namespace)
1619
1646
  ...otelResourceAttrs,
1620
1647
  // OTEL_SERVICE_NAME explicitly overrides service.name
1621
- ...otelServiceName ? { [ATTR_SERVICE_NAME]: otelServiceName } : {},
1648
+ ...otelServiceName ? { [SERVICE_NAME]: otelServiceName } : {},
1622
1649
  // Highest priority: Sentry SDK telemetry attrs (cannot be overridden by env vars)
1623
- [ATTR_SERVICE_VERSION]: SDK_VERSION,
1650
+ [SERVICE_VERSION]: SDK_VERSION,
1624
1651
  [ATTR_TELEMETRY_SDK_LANGUAGE]: SDK_INFO[ATTR_TELEMETRY_SDK_LANGUAGE],
1625
1652
  [ATTR_TELEMETRY_SDK_NAME]: SDK_INFO[ATTR_TELEMETRY_SDK_NAME],
1626
1653
  [ATTR_TELEMETRY_SDK_VERSION]: SDK_INFO[ATTR_TELEMETRY_SDK_VERSION]
@@ -1628,4 +1655,4 @@ function getSentryResource(serviceNameFallback) {
1628
1655
  }
1629
1656
 
1630
1657
  export { startSpanManual as A, suppressTracing as B, withActiveSpan as C, wrapClientClass as D, wrapContextManagerClass as E, wrapSamplingDecision as F, SEMANTIC_ATTRIBUTE_SENTRY_GRAPHQL_OPERATION as S, SENTRY_SCOPES_CONTEXT_KEY as a, SentryPropagator as b, SentrySampler as c, SentrySpanProcessor as d, buildContextWithSentryScopes as e, continueTrace as f, enhanceDscWithOpenTelemetryRootSpanName as g, getActiveSpan as h, getRequestSpanData as i, getScopesFromContext as j, getSentryResource as k, getSpanKind as l, getTraceContextForScope as m, isSentryRequestSpan as n, openTelemetrySetupCheck as o, setOpenTelemetryContextAsyncContextStrategy as p, setupEventContextTrace as q, spanHasAttributes as r, setIsSetup as s, spanHasEvents as t, spanHasKind as u, spanHasName as v, spanHasParentId as w, spanHasStatus as x, startInactiveSpan as y, startSpan as z };
1631
- //# sourceMappingURL=resource-CEl6olOs.js.map
1658
+ //# sourceMappingURL=resource-PMlHXvcP.js.map