@sentry/opentelemetry 8.0.0-beta.2 → 8.0.0-beta.4

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/esm/index.js CHANGED
@@ -7,6 +7,7 @@ import { SDK_VERSION, getClient, getDynamicSamplingContextFromClient, SEMANTIC_A
7
7
  export { getClient, getCurrentHubShim } from '@sentry/core';
8
8
  import { W3CBaggagePropagator, isTracingSuppressed, TraceState, suppressTracing as suppressTracing$1 } from '@opentelemetry/core';
9
9
  import { SamplingDecision } from '@opentelemetry/sdk-trace-base';
10
+ import { registerInstrumentations } from '@opentelemetry/instrumentation';
10
11
 
11
12
  /**
12
13
  * Check if a given span has attributes.
@@ -285,7 +286,10 @@ function parseSpanDescription(span) {
285
286
  const name = spanHasName(span) ? span.name : '<unknown>';
286
287
 
287
288
  // if http.method exists, this is an http request span
288
- const httpMethod = attributes[SEMATTRS_HTTP_METHOD];
289
+ //
290
+ // TODO: Referencing `http.request.method` is a temporary workaround until the semantic
291
+ // conventions export an attribute key for it.
292
+ const httpMethod = attributes['http.request.method'] || attributes[SEMATTRS_HTTP_METHOD];
289
293
  if (httpMethod) {
290
294
  return descriptionForHttpMethod({ attributes, name, kind: getSpanKind(span) }, httpMethod);
291
295
  }
@@ -1085,15 +1089,6 @@ function suppressTracing(callback) {
1085
1089
  return context.with(ctx, callback);
1086
1090
  }
1087
1091
 
1088
- /**
1089
- * Ensure the global hub is setup.
1090
- *
1091
- * @deprecated This will be removed in the next major version.
1092
- */
1093
- function setupGlobalHub() {
1094
- // noop
1095
- }
1096
-
1097
1092
  /** Ensure the `trace` context is set on all events. */
1098
1093
  function setupEventContextTrace(client) {
1099
1094
  client.on('preprocessEvent', event => {
@@ -1116,12 +1111,13 @@ function setupEventContextTrace(client) {
1116
1111
  ...event.contexts,
1117
1112
  };
1118
1113
 
1114
+ const rootSpan = getRootSpan(span);
1115
+
1119
1116
  event.sdkProcessingMetadata = {
1120
- dynamicSamplingContext: getDynamicSamplingContextFromSpan(span),
1117
+ dynamicSamplingContext: getDynamicSamplingContextFromSpan(rootSpan),
1121
1118
  ...event.sdkProcessingMetadata,
1122
1119
  };
1123
1120
 
1124
- const rootSpan = getRootSpan(span);
1125
1121
  const transactionName = spanHasName(rootSpan) ? rootSpan.name : undefined;
1126
1122
  if (transactionName && !event.transaction) {
1127
1123
  event.transaction = transactionName;
@@ -1554,7 +1550,7 @@ function maybeSend(spans) {
1554
1550
  transactionEvent.spans = spans;
1555
1551
 
1556
1552
  const measurements = timedEventsToMeasurements(span.events);
1557
- if (Object.keys(measurements).length) {
1553
+ if (measurements) {
1558
1554
  transactionEvent.measurements = measurements;
1559
1555
  }
1560
1556
 
@@ -1692,6 +1688,7 @@ function createAndFinishSpanForOtelSpan(node, spans, remaining) {
1692
1688
  op,
1693
1689
  origin,
1694
1690
  _metrics_summary: getMetricSummaryJsonForSpan(span ),
1691
+ measurements: timedEventsToMeasurements(span.events),
1695
1692
  });
1696
1693
 
1697
1694
  spans.push(spanJSON);
@@ -1896,11 +1893,18 @@ class SentrySampler {
1896
1893
 
1897
1894
  const parentSampled = parentSpan ? getParentSampled(parentSpan, traceId, spanName) : undefined;
1898
1895
 
1899
- // If we encounter a span emitted by Next.js, we do not want to sample it
1900
- // The reason for this is that the data quality of the spans varies, it is different per version of Next,
1901
- // and we need to keep our manual instrumentation around for the edge runtime anyhow.
1902
- // BUT we only do this if we don't have a parent span with a sampling decision yet
1903
- if (spanAttributes['next.span_type'] && typeof parentSampled !== 'boolean') {
1896
+ const mutableSamplingDecision = { decision: true };
1897
+ this._client.emit(
1898
+ 'beforeSampling',
1899
+ {
1900
+ spanAttributes: spanAttributes,
1901
+ spanName: spanName,
1902
+ parentSampled: parentSampled,
1903
+ parentContext: parentContext,
1904
+ },
1905
+ mutableSamplingDecision,
1906
+ );
1907
+ if (!mutableSamplingDecision.decision) {
1904
1908
  return { decision: SamplingDecision.NOT_RECORD, traceState: traceState };
1905
1909
  }
1906
1910
 
@@ -1978,5 +1982,15 @@ function getParentSampled(parentSpan, traceId, spanName) {
1978
1982
  return undefined;
1979
1983
  }
1980
1984
 
1981
- export { SentryPropagator, SentrySampler, SentrySpanProcessor, continueTrace, getActiveSpan, getDynamicSamplingContextFromSpan, getRequestSpanData, getScopesFromContext, getSpanKind, isSentryRequestSpan, openTelemetrySetupCheck, setOpenTelemetryContextAsyncContextStrategy, setupEventContextTrace, setupGlobalHub, spanHasAttributes, spanHasEvents, spanHasKind, spanHasName, spanHasParentId, spanHasStatus, startInactiveSpan, startSpan, startSpanManual, suppressTracing, withActiveSpan, wrapClientClass, wrapContextManagerClass };
1985
+ /**
1986
+ * This method takes an OpenTelemetry instrumentation or
1987
+ * array of instrumentations and registers them with OpenTelemetry.
1988
+ */
1989
+ function addOpenTelemetryInstrumentation(...instrumentations) {
1990
+ registerInstrumentations({
1991
+ instrumentations,
1992
+ });
1993
+ }
1994
+
1995
+ export { SentryPropagator, SentrySampler, SentrySpanProcessor, addOpenTelemetryInstrumentation, continueTrace, getActiveSpan, getDynamicSamplingContextFromSpan, getRequestSpanData, getScopesFromContext, getSpanKind, isSentryRequestSpan, openTelemetrySetupCheck, setOpenTelemetryContextAsyncContextStrategy, setupEventContextTrace, spanHasAttributes, spanHasEvents, spanHasKind, spanHasName, spanHasParentId, spanHasStatus, startInactiveSpan, startSpan, startSpanManual, suppressTracing, withActiveSpan, wrapClientClass, wrapContextManagerClass };
1982
1996
  //# sourceMappingURL=index.js.map