@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.
package/README.md CHANGED
@@ -28,7 +28,6 @@ Note that `@sentry/opentelemetry` depends on the following peer dependencies:
28
28
 
29
29
  - `@opentelemetry/api` version `1.0.0` or greater
30
30
  - `@opentelemetry/core` version `1.0.0` or greater
31
- - `@opentelemetry/semantic-conventions` version `1.0.0` or greater
32
31
  - `@opentelemetry/sdk-trace-base` version `1.0.0` or greater, or a package that implements that, like
33
32
  `@opentelemetry/sdk-node`.
34
33
 
@@ -1,9 +1,9 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
3
  const core = require('@sentry/core');
4
- const resource = require('./resource-CTgtEOmw.js');
4
+ const resource = require('./resource-DEULI4zI.js');
5
5
  require('@opentelemetry/api');
6
- require('@opentelemetry/semantic-conventions');
6
+ require('@sentry/conventions/attributes');
7
7
  require('@opentelemetry/core');
8
8
  require('./debug-build-CQngOfDt.js');
9
9
  require('@opentelemetry/sdk-trace-base');
@@ -1,11 +1,11 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
- const resource = require('./resource-CTgtEOmw.js');
3
+ const resource = require('./resource-DEULI4zI.js');
4
4
  const core = require('@sentry/core');
5
5
  const api = require('@opentelemetry/api');
6
6
  const node_async_hooks = require('node:async_hooks');
7
7
  const node_events = require('node:events');
8
- require('@opentelemetry/semantic-conventions');
8
+ require('@sentry/conventions/attributes');
9
9
  require('@opentelemetry/core');
10
10
  require('./debug-build-CQngOfDt.js');
11
11
  require('@opentelemetry/sdk-trace-base');
@@ -1,6 +1,6 @@
1
1
  const api = require('@opentelemetry/api');
2
2
  const core = require('@sentry/core');
3
- const semanticConventions = require('@opentelemetry/semantic-conventions');
3
+ const attributes = require('@sentry/conventions/attributes');
4
4
  const core$1 = require('@opentelemetry/core');
5
5
  const debugBuild = require('./debug-build-CQngOfDt.js');
6
6
  const sdkTraceBase = require('@opentelemetry/sdk-trace-base');
@@ -46,11 +46,11 @@ function getRequestSpanData(span) {
46
46
  if (!spanHasAttributes(span)) {
47
47
  return {};
48
48
  }
49
- const maybeUrlAttribute = span.attributes[semanticConventions.ATTR_URL_FULL] || span.attributes[semanticConventions.SEMATTRS_HTTP_URL];
49
+ const maybeUrlAttribute = span.attributes[attributes.URL_FULL] || span.attributes[attributes.HTTP_URL];
50
50
  const data = {
51
51
  url: maybeUrlAttribute,
52
- // eslint-disable-next-line deprecation/deprecation
53
- "http.method": span.attributes[semanticConventions.ATTR_HTTP_REQUEST_METHOD] || span.attributes[semanticConventions.SEMATTRS_HTTP_METHOD]
52
+ // eslint-disable-next-line typescript/no-deprecated
53
+ "http.method": span.attributes[attributes.HTTP_REQUEST_METHOD] || span.attributes[attributes.HTTP_METHOD]
54
54
  };
55
55
  if (!data["http.method"] && data.url) {
56
56
  data["http.method"] = "GET";
@@ -138,8 +138,8 @@ function isSentryRequestSpan(span) {
138
138
  if (!spanHasAttributes(span)) {
139
139
  return false;
140
140
  }
141
- const { attributes } = span;
142
- const httpUrl = attributes[semanticConventions.SEMATTRS_HTTP_URL] || attributes[semanticConventions.ATTR_URL_FULL];
141
+ const { attributes: attributes$1 } = span;
142
+ const httpUrl = attributes$1[attributes.HTTP_URL] || attributes$1[attributes.URL_FULL];
143
143
  if (!httpUrl) {
144
144
  return false;
145
145
  }
@@ -166,35 +166,35 @@ function getSamplingDecision(spanContext) {
166
166
  return void 0;
167
167
  }
168
168
 
169
- function inferSpanData(spanName, attributes, kind) {
170
- const httpMethod = attributes[semanticConventions.ATTR_HTTP_REQUEST_METHOD] || attributes[semanticConventions.SEMATTRS_HTTP_METHOD];
169
+ function inferSpanData(spanName, attributes$1, kind) {
170
+ const httpMethod = attributes$1[attributes.HTTP_REQUEST_METHOD] || attributes$1[attributes.HTTP_METHOD];
171
171
  if (httpMethod) {
172
- return descriptionForHttpMethod({ attributes, name: spanName, kind }, httpMethod);
172
+ return descriptionForHttpMethod({ attributes: attributes$1, name: spanName, kind }, httpMethod);
173
173
  }
174
- const dbSystem = attributes[semanticConventions.ATTR_DB_SYSTEM_NAME] || attributes[semanticConventions.SEMATTRS_DB_SYSTEM];
175
- const opIsCache = typeof attributes[core.SEMANTIC_ATTRIBUTE_SENTRY_OP] === "string" && attributes[core.SEMANTIC_ATTRIBUTE_SENTRY_OP].startsWith("cache.");
174
+ const dbSystem = attributes$1[attributes.DB_SYSTEM_NAME] || attributes$1[attributes.DB_SYSTEM];
175
+ const opIsCache = typeof attributes$1[core.SEMANTIC_ATTRIBUTE_SENTRY_OP] === "string" && attributes$1[core.SEMANTIC_ATTRIBUTE_SENTRY_OP].startsWith("cache.");
176
176
  if (dbSystem && !opIsCache) {
177
- return descriptionForDbSystem({ attributes, name: spanName });
177
+ return descriptionForDbSystem({ attributes: attributes$1, name: spanName });
178
178
  }
179
- const customSourceOrRoute = attributes[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] === "custom" ? "custom" : "route";
180
- const rpcService = attributes[semanticConventions.SEMATTRS_RPC_SERVICE];
179
+ const customSourceOrRoute = attributes$1[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] === "custom" ? "custom" : "route";
180
+ const rpcService = attributes$1[attributes.RPC_SERVICE];
181
181
  if (rpcService) {
182
182
  return {
183
- ...getUserUpdatedNameAndSource(spanName, attributes, "route"),
183
+ ...getUserUpdatedNameAndSource(spanName, attributes$1, "route"),
184
184
  op: "rpc"
185
185
  };
186
186
  }
187
- const messagingSystem = attributes[semanticConventions.SEMATTRS_MESSAGING_SYSTEM];
187
+ const messagingSystem = attributes$1[attributes.MESSAGING_SYSTEM];
188
188
  if (messagingSystem) {
189
189
  return {
190
- ...getUserUpdatedNameAndSource(spanName, attributes, customSourceOrRoute),
190
+ ...getUserUpdatedNameAndSource(spanName, attributes$1, customSourceOrRoute),
191
191
  op: "message"
192
192
  };
193
193
  }
194
- const faasTrigger = attributes[semanticConventions.SEMATTRS_FAAS_TRIGGER];
194
+ const faasTrigger = attributes$1[attributes.FAAS_TRIGGER];
195
195
  if (faasTrigger) {
196
196
  return {
197
- ...getUserUpdatedNameAndSource(spanName, attributes, customSourceOrRoute),
197
+ ...getUserUpdatedNameAndSource(spanName, attributes$1, customSourceOrRoute),
198
198
  op: faasTrigger.toString()
199
199
  };
200
200
  }
@@ -206,19 +206,19 @@ function parseSpanDescription(span) {
206
206
  const kind = getSpanKind(span);
207
207
  return inferSpanData(name, attributes, kind);
208
208
  }
209
- function descriptionForDbSystem({ attributes, name }) {
210
- const userDefinedName = attributes[core.SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME];
209
+ function descriptionForDbSystem({ attributes: attributes$1, name }) {
210
+ const userDefinedName = attributes$1[core.SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME];
211
211
  if (typeof userDefinedName === "string") {
212
212
  return {
213
213
  op: "db",
214
214
  description: userDefinedName,
215
- source: attributes[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] || "custom"
215
+ source: attributes$1[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] || "custom"
216
216
  };
217
217
  }
218
- if (attributes[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] === "custom") {
218
+ if (attributes$1[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] === "custom") {
219
219
  return { op: "db", description: name, source: "custom" };
220
220
  }
221
- const statement = attributes[semanticConventions.SEMATTRS_DB_STATEMENT];
221
+ const statement = attributes$1[attributes.DB_STATEMENT];
222
222
  const description = statement ? statement.toString() : name;
223
223
  return { op: "db", description, source: "task" };
224
224
  }
@@ -278,10 +278,10 @@ function getGraphqlOperationNamesFromAttribute(attr) {
278
278
  }
279
279
  return `${attr}`;
280
280
  }
281
- function getSanitizedUrl(attributes, kind) {
282
- const httpTarget = attributes[semanticConventions.SEMATTRS_HTTP_TARGET];
283
- const httpUrl = attributes[semanticConventions.SEMATTRS_HTTP_URL] || attributes[semanticConventions.ATTR_URL_FULL];
284
- const httpRoute = attributes[semanticConventions.ATTR_HTTP_ROUTE];
281
+ function getSanitizedUrl(attributes$1, kind) {
282
+ const httpTarget = attributes$1[attributes.HTTP_TARGET];
283
+ const httpUrl = attributes$1[attributes.HTTP_URL] || attributes$1[attributes.URL_FULL];
284
+ const httpRoute = attributes$1[attributes.HTTP_ROUTE];
285
285
  const parsedUrl = typeof httpUrl === "string" ? core.parseUrl(httpUrl) : void 0;
286
286
  const url = parsedUrl ? core.getSanitizedUrlString(parsedUrl) : void 0;
287
287
  const query = parsedUrl?.search || void 0;
@@ -537,7 +537,7 @@ function getExistingSentryTrace(carrier) {
537
537
  }
538
538
  function getCurrentURL(span) {
539
539
  const spanData = core.spanToJSON(span).data;
540
- const urlAttribute = spanData[semanticConventions.SEMATTRS_HTTP_URL] || spanData[semanticConventions.ATTR_URL_FULL];
540
+ const urlAttribute = spanData[attributes.HTTP_URL] || spanData[attributes.URL_FULL];
541
541
  if (typeof urlAttribute === "string") {
542
542
  return urlAttribute;
543
543
  }
@@ -998,9 +998,9 @@ function mapStatus(span) {
998
998
  return { code: core.SPAN_STATUS_ERROR, message: "unknown_error" };
999
999
  }
1000
1000
  }
1001
- function inferStatusFromAttributes(attributes) {
1002
- const httpCodeAttribute = attributes[semanticConventions.ATTR_HTTP_RESPONSE_STATUS_CODE] || attributes[semanticConventions.SEMATTRS_HTTP_STATUS_CODE];
1003
- const grpcCodeAttribute = attributes[semanticConventions.SEMATTRS_RPC_GRPC_STATUS_CODE];
1001
+ function inferStatusFromAttributes(attributes$1) {
1002
+ const httpCodeAttribute = attributes$1[attributes.HTTP_RESPONSE_STATUS_CODE] || attributes$1[attributes.HTTP_STATUS_CODE];
1003
+ const grpcCodeAttribute = attributes$1[attributes.RPC_GRPC_STATUS_CODE];
1004
1004
  const numberHttpCode = typeof httpCodeAttribute === "number" ? httpCodeAttribute : typeof httpCodeAttribute === "string" ? parseInt(httpCodeAttribute) : void 0;
1005
1005
  if (typeof numberHttpCode === "number") {
1006
1006
  return core.getSpanStatusFromHttpCode(numberHttpCode);
@@ -1153,7 +1153,7 @@ function createTransactionForOtelSpan(span) {
1153
1153
  const { op, description, data, origin = "manual", source } = getSpanData(span);
1154
1154
  const capturedSpanScopes = core.getCapturedScopesOnSpan(span);
1155
1155
  const sampleRate = span.attributes[core.SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE];
1156
- const attributes = {
1156
+ const attributes$1 = {
1157
1157
  [core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source,
1158
1158
  [core.SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: sampleRate,
1159
1159
  [core.SEMANTIC_ATTRIBUTE_SENTRY_OP]: op,
@@ -1169,14 +1169,14 @@ function createTransactionForOtelSpan(span) {
1169
1169
  parent_span_id,
1170
1170
  span_id,
1171
1171
  trace_id,
1172
- data: attributes,
1172
+ data: attributes$1,
1173
1173
  origin,
1174
1174
  op,
1175
1175
  status: core.getStatusMessage(status),
1176
1176
  // As per protocol, span status is allowed to be undefined
1177
1177
  links: core.convertSpanLinksForEnvelope(links)
1178
1178
  };
1179
- const statusCode = attributes[semanticConventions.ATTR_HTTP_RESPONSE_STATUS_CODE];
1179
+ const statusCode = attributes$1[attributes.HTTP_RESPONSE_STATUS_CODE];
1180
1180
  const responseContext = typeof statusCode === "number" ? { response: { status_code: statusCode } } : void 0;
1181
1181
  const transactionEvent = {
1182
1182
  contexts: {
@@ -1279,14 +1279,14 @@ function removeSentryAttributes(data) {
1279
1279
  return cleanedData;
1280
1280
  }
1281
1281
  function getData(span) {
1282
- const attributes = span.attributes;
1282
+ const attributes$1 = span.attributes;
1283
1283
  const data = {};
1284
1284
  if (span.kind !== api.SpanKind.INTERNAL) {
1285
1285
  data["otel.kind"] = api.SpanKind[span.kind];
1286
1286
  }
1287
- const maybeHttpStatusCodeAttribute = attributes[semanticConventions.SEMATTRS_HTTP_STATUS_CODE];
1287
+ const maybeHttpStatusCodeAttribute = attributes$1[attributes.HTTP_STATUS_CODE];
1288
1288
  if (maybeHttpStatusCodeAttribute) {
1289
- data[semanticConventions.ATTR_HTTP_RESPONSE_STATUS_CODE] = maybeHttpStatusCodeAttribute;
1289
+ data[attributes.HTTP_RESPONSE_STATUS_CODE] = maybeHttpStatusCodeAttribute;
1290
1290
  }
1291
1291
  const requestData = getRequestSpanData(span);
1292
1292
  if (requestData.url) {
@@ -1303,8 +1303,13 @@ function getData(span) {
1303
1303
 
1304
1304
  class SentrySpanProcessor {
1305
1305
  constructor(options) {
1306
+ this._unsubscribePreprocessSpan = void 0;
1306
1307
  setIsSetup("SentrySpanProcessor");
1307
1308
  this._exporter = new SentrySpanExporter(options);
1309
+ this._client = options?.client ?? core.getClient();
1310
+ if (this._client && core.hasSpanStreamingEnabled(this._client)) {
1311
+ this._unsubscribePreprocessSpan = this._client.on("preprocessSpan", backfillStreamedSpanDataFromOtel);
1312
+ }
1308
1313
  }
1309
1314
  /**
1310
1315
  * @inheritDoc
@@ -1316,6 +1321,7 @@ class SentrySpanProcessor {
1316
1321
  * @inheritDoc
1317
1322
  */
1318
1323
  async shutdown() {
1324
+ this._unsubscribePreprocessSpan?.();
1319
1325
  this._exporter.clear();
1320
1326
  }
1321
1327
  /**
@@ -1340,21 +1346,38 @@ class SentrySpanProcessor {
1340
1346
  core.setCapturedScopesOnSpan(span, scopes.scope, scopes.isolationScope);
1341
1347
  }
1342
1348
  core.logSpanStart(span);
1343
- const client = core.getClient();
1344
- client?.emit("spanStart", span);
1349
+ this._client?.emit("spanStart", span);
1345
1350
  }
1346
1351
  /** @inheritDoc */
1347
1352
  onEnd(span) {
1348
1353
  core.logSpanEnd(span);
1349
- const client = core.getClient();
1350
- client?.emit("spanEnd", span);
1351
- if (client && core.hasSpanStreamingEnabled(client)) {
1352
- client.emit("afterSpanEnd", span);
1354
+ this._client?.emit("spanEnd", span);
1355
+ if (this._client && core.hasSpanStreamingEnabled(this._client)) {
1356
+ this._client.emit("afterSpanEnd", span);
1353
1357
  } else {
1354
1358
  this._exporter.export(span);
1355
1359
  }
1356
1360
  }
1357
1361
  }
1362
+ function backfillStreamedSpanDataFromOtel(spanJSON, hint) {
1363
+ const attributes = spanJSON.attributes;
1364
+ if (!attributes) {
1365
+ return;
1366
+ }
1367
+ const kind = hint?.spanKind ?? api.SpanKind.INTERNAL;
1368
+ const { op, description, source, data } = inferSpanData(spanJSON.name, attributes, kind);
1369
+ spanJSON.name = description;
1370
+ core.safeSetSpanJSONAttributes(spanJSON, {
1371
+ [core.SEMANTIC_ATTRIBUTE_SENTRY_OP]: op,
1372
+ [core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source,
1373
+ ...data
1374
+ });
1375
+ if (kind !== api.SpanKind.INTERNAL) {
1376
+ core.safeSetSpanJSONAttributes(spanJSON, {
1377
+ "otel.kind": api.SpanKind[kind]
1378
+ });
1379
+ }
1380
+ }
1358
1381
 
1359
1382
  class SentrySampler {
1360
1383
  constructor(client) {
@@ -1371,7 +1394,7 @@ class SentrySampler {
1371
1394
  if (!core.hasSpansEnabled(options)) {
1372
1395
  return wrapSamplingDecision({ decision: void 0, context, spanAttributes });
1373
1396
  }
1374
- const maybeSpanHttpMethod = spanAttributes[semanticConventions.SEMATTRS_HTTP_METHOD] || spanAttributes[semanticConventions.ATTR_HTTP_REQUEST_METHOD];
1397
+ const maybeSpanHttpMethod = spanAttributes[attributes.HTTP_METHOD] || spanAttributes[attributes.HTTP_REQUEST_METHOD];
1375
1398
  if (spanKind === api.SpanKind.CLIENT && maybeSpanHttpMethod && (!parentSpan || parentContext?.isRemote)) {
1376
1399
  if (!this._isSpanStreaming) {
1377
1400
  this._client.recordDroppedEvent("no_parent_span", "span");
@@ -1555,7 +1578,7 @@ function getBaseTraceState(context, spanAttributes) {
1555
1578
  const parentSpan = api.trace.getSpan(context);
1556
1579
  const parentContext = parentSpan?.spanContext();
1557
1580
  let traceState = parentContext?.traceState || new TraceState();
1558
- const url = spanAttributes[semanticConventions.SEMATTRS_HTTP_URL] || spanAttributes[semanticConventions.ATTR_URL_FULL];
1581
+ const url = spanAttributes[attributes.HTTP_URL] || spanAttributes[attributes.URL_FULL];
1559
1582
  if (url && typeof url === "string") {
1560
1583
  traceState = traceState.set(SENTRY_TRACE_STATE_URL, url);
1561
1584
  }
@@ -1566,6 +1589,10 @@ function getValidSpan(context) {
1566
1589
  return span && api.isSpanContextValid(span.spanContext()) ? span : void 0;
1567
1590
  }
1568
1591
 
1592
+ const ATTR_TELEMETRY_SDK_LANGUAGE = "telemetry.sdk.language";
1593
+ const ATTR_TELEMETRY_SDK_NAME = "telemetry.sdk.name";
1594
+ const ATTR_TELEMETRY_SDK_VERSION = "telemetry.sdk.version";
1595
+ const SEMRESATTRS_SERVICE_NAMESPACE = "service.namespace";
1569
1596
  class SentryResource {
1570
1597
  constructor(attributes) {
1571
1598
  this._attributes = attributes;
@@ -1611,18 +1638,18 @@ function getSentryResource(serviceNameFallback) {
1611
1638
  const otelResourceAttrs = parseOtelResourceAttributes(env.OTEL_RESOURCE_ATTRIBUTES);
1612
1639
  return new SentryResource({
1613
1640
  // Lowest priority: Sentry defaults
1614
- // eslint-disable-next-line deprecation/deprecation
1615
- [semanticConventions.SEMRESATTRS_SERVICE_NAMESPACE]: "sentry",
1616
- [semanticConventions.ATTR_SERVICE_NAME]: serviceNameFallback,
1641
+ // eslint-disable-next-line typescript/no-deprecated
1642
+ [SEMRESATTRS_SERVICE_NAMESPACE]: "sentry",
1643
+ [attributes.SERVICE_NAME]: serviceNameFallback,
1617
1644
  // OTEL_RESOURCE_ATTRIBUTES overrides defaults (including service.name and service.namespace)
1618
1645
  ...otelResourceAttrs,
1619
1646
  // OTEL_SERVICE_NAME explicitly overrides service.name
1620
- ...otelServiceName ? { [semanticConventions.ATTR_SERVICE_NAME]: otelServiceName } : {},
1647
+ ...otelServiceName ? { [attributes.SERVICE_NAME]: otelServiceName } : {},
1621
1648
  // Highest priority: Sentry SDK telemetry attrs (cannot be overridden by env vars)
1622
- [semanticConventions.ATTR_SERVICE_VERSION]: core.SDK_VERSION,
1623
- [semanticConventions.ATTR_TELEMETRY_SDK_LANGUAGE]: core$1.SDK_INFO[semanticConventions.ATTR_TELEMETRY_SDK_LANGUAGE],
1624
- [semanticConventions.ATTR_TELEMETRY_SDK_NAME]: core$1.SDK_INFO[semanticConventions.ATTR_TELEMETRY_SDK_NAME],
1625
- [semanticConventions.ATTR_TELEMETRY_SDK_VERSION]: core$1.SDK_INFO[semanticConventions.ATTR_TELEMETRY_SDK_VERSION]
1649
+ [attributes.SERVICE_VERSION]: core.SDK_VERSION,
1650
+ [ATTR_TELEMETRY_SDK_LANGUAGE]: core$1.SDK_INFO[ATTR_TELEMETRY_SDK_LANGUAGE],
1651
+ [ATTR_TELEMETRY_SDK_NAME]: core$1.SDK_INFO[ATTR_TELEMETRY_SDK_NAME],
1652
+ [ATTR_TELEMETRY_SDK_VERSION]: core$1.SDK_INFO[ATTR_TELEMETRY_SDK_VERSION]
1626
1653
  });
1627
1654
  }
1628
1655
 
@@ -1659,4 +1686,4 @@ exports.withActiveSpan = withActiveSpan;
1659
1686
  exports.wrapClientClass = wrapClientClass;
1660
1687
  exports.wrapContextManagerClass = wrapContextManagerClass;
1661
1688
  exports.wrapSamplingDecision = wrapSamplingDecision;
1662
- //# sourceMappingURL=resource-CTgtEOmw.js.map
1689
+ //# sourceMappingURL=resource-DEULI4zI.js.map