@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.
@@ -9,6 +9,12 @@ import { TraceState, W3CBaggagePropagator, isTracingSuppressed, suppressTracing
9
9
  import { SamplingDecision } from '@opentelemetry/sdk-trace-base';
10
10
  import { registerInstrumentations } from '@opentelemetry/instrumentation';
11
11
 
12
+ /** If this attribute is true, it means that the parent is a remote span. */
13
+ const SEMANTIC_ATTRIBUTE_SENTRY_PARENT_IS_REMOTE = 'sentry.parentIsRemote';
14
+
15
+ // These are not standardized yet, but used by the graphql instrumentation
16
+ const SEMANTIC_ATTRIBUTE_SENTRY_GRAPHQL_OPERATION = 'sentry.graphql.operation';
17
+
12
18
  /**
13
19
  * Check if a given span has attributes.
14
20
  * This is necessary because the base `Span` type does not have attributes,
@@ -28,7 +34,7 @@ function spanHasAttributes(
28
34
  */
29
35
  function spanHasKind(span) {
30
36
  const castSpan = span ;
31
- return !!castSpan.kind;
37
+ return typeof castSpan.kind === 'number';
32
38
  }
33
39
 
34
40
  /**
@@ -367,8 +373,16 @@ function descriptionForHttpMethod(
367
373
  return { op: opParts.join('.'), description: name, source: 'custom' };
368
374
  }
369
375
 
370
- // Ex. description="GET /api/users".
371
- const description = `${httpMethod} ${urlPath}`;
376
+ const graphqlOperationsAttribute = attributes[SEMANTIC_ATTRIBUTE_SENTRY_GRAPHQL_OPERATION];
377
+
378
+ // Ex. GET /api/users
379
+ const baseDescription = `${httpMethod} ${urlPath}`;
380
+
381
+ // When the http span has a graphql operation, append it to the description
382
+ // We add these in the graphqlIntegration
383
+ const description = graphqlOperationsAttribute
384
+ ? `${baseDescription} (${getGraphqlOperationNamesFromAttribute(graphqlOperationsAttribute)})`
385
+ : baseDescription;
372
386
 
373
387
  // If `httpPath` is a root path, then we can categorize the transaction source as route.
374
388
  const source = hasRoute || urlPath === '/' ? 'route' : 'url';
@@ -393,6 +407,22 @@ function descriptionForHttpMethod(
393
407
  };
394
408
  }
395
409
 
410
+ function getGraphqlOperationNamesFromAttribute(attr) {
411
+ if (Array.isArray(attr)) {
412
+ const sorted = attr.slice().sort();
413
+
414
+ // Up to 5 items, we just add all of them
415
+ if (sorted.length <= 5) {
416
+ return sorted.join(', ');
417
+ } else {
418
+ // Else, we add the first 5 and the diff of other operations
419
+ return `${sorted.slice(0, 5).join(', ')}, +${sorted.length - 5}`;
420
+ }
421
+ }
422
+
423
+ return `${attr}`;
424
+ }
425
+
396
426
  /** Exported for tests only */
397
427
  function getSanitizedUrl(
398
428
  attributes,
@@ -1315,9 +1345,6 @@ function wrapContextManagerClass(
1315
1345
  return SentryContextManager ;
1316
1346
  }
1317
1347
 
1318
- /** If this attribute is true, it means that the parent is a remote span. */
1319
- const SEMANTIC_ATTRIBUTE_SENTRY_PARENT_IS_REMOTE = 'sentry.parentIsRemote';
1320
-
1321
1348
  /**
1322
1349
  * This function runs through a list of OTEL Spans, and wraps them in an `SpanNode`
1323
1350
  * where each node holds a reference to their parent node.
@@ -2100,5 +2127,5 @@ function addOpenTelemetryInstrumentation(...instrumentations) {
2100
2127
  });
2101
2128
  }
2102
2129
 
2103
- export { SentryPropagator, SentrySampler, SentrySpanProcessor, addOpenTelemetryInstrumentation, continueTrace, enhanceDscWithOpenTelemetryRootSpanName, generateSpanContextForPropagationContext, getActiveSpan, getPropagationContextFromSpan, getRequestSpanData, getScopesFromContext, getSpanKind, isSentryRequestSpan, openTelemetrySetupCheck, setOpenTelemetryContextAsyncContextStrategy, setupEventContextTrace, spanHasAttributes, spanHasEvents, spanHasKind, spanHasName, spanHasParentId, spanHasStatus, startInactiveSpan, startSpan, startSpanManual, suppressTracing, withActiveSpan, wrapClientClass, wrapContextManagerClass, wrapSamplingDecision };
2130
+ export { SEMANTIC_ATTRIBUTE_SENTRY_GRAPHQL_OPERATION, SentryPropagator, SentrySampler, SentrySpanProcessor, addOpenTelemetryInstrumentation, continueTrace, enhanceDscWithOpenTelemetryRootSpanName, generateSpanContextForPropagationContext, getActiveSpan, getPropagationContextFromSpan, getRequestSpanData, getScopesFromContext, getSpanKind, isSentryRequestSpan, openTelemetrySetupCheck, setOpenTelemetryContextAsyncContextStrategy, setupEventContextTrace, spanHasAttributes, spanHasEvents, spanHasKind, spanHasName, spanHasParentId, spanHasStatus, startInactiveSpan, startSpan, startSpanManual, suppressTracing, withActiveSpan, wrapClientClass, wrapContextManagerClass, wrapSamplingDecision };
2104
2131
  //# sourceMappingURL=index.js.map