@sentry/opentelemetry 8.24.0 → 8.25.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.
@@ -12,6 +12,12 @@ const core$1 = require('@opentelemetry/core');
12
12
  const sdkTraceBase = require('@opentelemetry/sdk-trace-base');
13
13
  const instrumentation = require('@opentelemetry/instrumentation');
14
14
 
15
+ /** If this attribute is true, it means that the parent is a remote span. */
16
+ const SEMANTIC_ATTRIBUTE_SENTRY_PARENT_IS_REMOTE = 'sentry.parentIsRemote';
17
+
18
+ // These are not standardized yet, but used by the graphql instrumentation
19
+ const SEMANTIC_ATTRIBUTE_SENTRY_GRAPHQL_OPERATION = 'sentry.graphql.operation';
20
+
15
21
  /**
16
22
  * Check if a given span has attributes.
17
23
  * This is necessary because the base `Span` type does not have attributes,
@@ -31,7 +37,7 @@ function spanHasAttributes(
31
37
  */
32
38
  function spanHasKind(span) {
33
39
  const castSpan = span ;
34
- return !!castSpan.kind;
40
+ return typeof castSpan.kind === 'number';
35
41
  }
36
42
 
37
43
  /**
@@ -370,8 +376,16 @@ function descriptionForHttpMethod(
370
376
  return { op: opParts.join('.'), description: name, source: 'custom' };
371
377
  }
372
378
 
373
- // Ex. description="GET /api/users".
374
- const description = `${httpMethod} ${urlPath}`;
379
+ const graphqlOperationsAttribute = attributes[SEMANTIC_ATTRIBUTE_SENTRY_GRAPHQL_OPERATION];
380
+
381
+ // Ex. GET /api/users
382
+ const baseDescription = `${httpMethod} ${urlPath}`;
383
+
384
+ // When the http span has a graphql operation, append it to the description
385
+ // We add these in the graphqlIntegration
386
+ const description = graphqlOperationsAttribute
387
+ ? `${baseDescription} (${getGraphqlOperationNamesFromAttribute(graphqlOperationsAttribute)})`
388
+ : baseDescription;
375
389
 
376
390
  // If `httpPath` is a root path, then we can categorize the transaction source as route.
377
391
  const source = hasRoute || urlPath === '/' ? 'route' : 'url';
@@ -396,6 +410,22 @@ function descriptionForHttpMethod(
396
410
  };
397
411
  }
398
412
 
413
+ function getGraphqlOperationNamesFromAttribute(attr) {
414
+ if (Array.isArray(attr)) {
415
+ const sorted = attr.slice().sort();
416
+
417
+ // Up to 5 items, we just add all of them
418
+ if (sorted.length <= 5) {
419
+ return sorted.join(', ');
420
+ } else {
421
+ // Else, we add the first 5 and the diff of other operations
422
+ return `${sorted.slice(0, 5).join(', ')}, +${sorted.length - 5}`;
423
+ }
424
+ }
425
+
426
+ return `${attr}`;
427
+ }
428
+
399
429
  /** Exported for tests only */
400
430
  function getSanitizedUrl(
401
431
  attributes,
@@ -1318,9 +1348,6 @@ function wrapContextManagerClass(
1318
1348
  return SentryContextManager ;
1319
1349
  }
1320
1350
 
1321
- /** If this attribute is true, it means that the parent is a remote span. */
1322
- const SEMANTIC_ATTRIBUTE_SENTRY_PARENT_IS_REMOTE = 'sentry.parentIsRemote';
1323
-
1324
1351
  /**
1325
1352
  * This function runs through a list of OTEL Spans, and wraps them in an `SpanNode`
1326
1353
  * where each node holds a reference to their parent node.
@@ -2106,6 +2133,7 @@ function addOpenTelemetryInstrumentation(...instrumentations) {
2106
2133
  exports.getClient = core.getClient;
2107
2134
  exports.getCurrentHubShim = core.getCurrentHubShim;
2108
2135
  exports.getDynamicSamplingContextFromSpan = core.getDynamicSamplingContextFromSpan;
2136
+ exports.SEMANTIC_ATTRIBUTE_SENTRY_GRAPHQL_OPERATION = SEMANTIC_ATTRIBUTE_SENTRY_GRAPHQL_OPERATION;
2109
2137
  exports.SentryPropagator = SentryPropagator;
2110
2138
  exports.SentrySampler = SentrySampler;
2111
2139
  exports.SentrySpanProcessor = SentrySpanProcessor;