@sentry/opentelemetry 10.38.0 → 10.39.0-alpha.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/build/cjs/index.js +75 -42
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.js +76 -43
- package/build/esm/index.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/build/types/propagator.d.ts +2 -8
- package/build/types/propagator.d.ts.map +1 -1
- package/build/types/spanExporter.d.ts +17 -2
- package/build/types/spanExporter.d.ts.map +1 -1
- package/build/types/spanProcessor.d.ts +3 -0
- package/build/types/spanProcessor.d.ts.map +1 -1
- package/build/types/streamingSpanExporter.d.ts +32 -0
- package/build/types/streamingSpanExporter.d.ts.map +1 -0
- package/build/types-ts3.8/propagator.d.ts +2 -8
- package/build/types-ts3.8/spanExporter.d.ts +17 -2
- package/build/types-ts3.8/spanProcessor.d.ts +3 -0
- package/build/types-ts3.8/streamingSpanExporter.d.ts +32 -0
- package/package.json +2 -2
package/build/esm/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
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 } from '@opentelemetry/semantic-conventions';
|
|
2
|
-
import { parseUrl, getSanitizedUrlString, SDK_VERSION, addNonEnumerableProperty, 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, parseBaggageHeader, SENTRY_BAGGAGE_KEY_PREFIX, generateSentryTraceHeader, generateTraceparentHeader,
|
|
3
|
-
export { getClient, getDynamicSamplingContextFromSpan } from '@sentry/core';
|
|
2
|
+
import { parseUrl, getSanitizedUrlString, SDK_VERSION, addNonEnumerableProperty, 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, 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, SpanBuffer, safeSetSpanJSONAttributes, captureSpan, logSpanEnd, addChildSpanToSpan, setCapturedScopesOnSpan, logSpanStart, parseSampleRate, _INTERNAL_safeMathRandom, sampleSpan } from '@sentry/core';
|
|
3
|
+
export { getClient, getDynamicSamplingContextFromSpan, shouldPropagateTraceForUrl } from '@sentry/core';
|
|
4
4
|
import * as api from '@opentelemetry/api';
|
|
5
5
|
import { trace, SpanKind, createContextKey, TraceFlags, propagation, INVALID_TRACEID, context, SpanStatusCode, ROOT_CONTEXT, isSpanContextValid } from '@opentelemetry/api';
|
|
6
6
|
import { TraceState, W3CBaggagePropagator, isTracingSuppressed, suppressTracing as suppressTracing$1 } from '@opentelemetry/core';
|
|
@@ -765,36 +765,6 @@ class SentryPropagator extends W3CBaggagePropagator {
|
|
|
765
765
|
}
|
|
766
766
|
}
|
|
767
767
|
|
|
768
|
-
const NOT_PROPAGATED_MESSAGE =
|
|
769
|
-
'[Tracing] Not injecting trace data for url because it does not match tracePropagationTargets:';
|
|
770
|
-
|
|
771
|
-
/**
|
|
772
|
-
* Check if a given URL should be propagated to or not.
|
|
773
|
-
* If no url is defined, or no trace propagation targets are defined, this will always return `true`.
|
|
774
|
-
* You can also optionally provide a decision map, to cache decisions and avoid repeated regex lookups.
|
|
775
|
-
*/
|
|
776
|
-
function shouldPropagateTraceForUrl(
|
|
777
|
-
url,
|
|
778
|
-
tracePropagationTargets,
|
|
779
|
-
decisionMap,
|
|
780
|
-
) {
|
|
781
|
-
if (typeof url !== 'string' || !tracePropagationTargets) {
|
|
782
|
-
return true;
|
|
783
|
-
}
|
|
784
|
-
|
|
785
|
-
const cachedDecision = decisionMap?.get(url);
|
|
786
|
-
if (cachedDecision !== undefined) {
|
|
787
|
-
DEBUG_BUILD && !cachedDecision && debug.log(NOT_PROPAGATED_MESSAGE, url);
|
|
788
|
-
return cachedDecision;
|
|
789
|
-
}
|
|
790
|
-
|
|
791
|
-
const decision = stringMatchesSomePattern(url, tracePropagationTargets);
|
|
792
|
-
decisionMap?.set(url, decision);
|
|
793
|
-
|
|
794
|
-
DEBUG_BUILD && !decision && debug.log(NOT_PROPAGATED_MESSAGE, url);
|
|
795
|
-
return decision;
|
|
796
|
-
}
|
|
797
|
-
|
|
798
768
|
/**
|
|
799
769
|
* Get propagation injection data for the given context.
|
|
800
770
|
* The additional options can be passed to override the scope and client that is otherwise derived from the context.
|
|
@@ -1648,7 +1618,7 @@ const DEFAULT_TIMEOUT = 300; // 5 min
|
|
|
1648
1618
|
/**
|
|
1649
1619
|
* A Sentry-specific exporter that converts OpenTelemetry Spans to Sentry Spans & Transactions.
|
|
1650
1620
|
*/
|
|
1651
|
-
class SentrySpanExporter
|
|
1621
|
+
class SentrySpanExporter {
|
|
1652
1622
|
/*
|
|
1653
1623
|
* A quick explanation on the buckets: We do bucketing of finished spans for efficiency. This span exporter is
|
|
1654
1624
|
* accumulating spans until a root span is encountered and then it flushes all the spans that are descendants of that
|
|
@@ -1979,6 +1949,9 @@ function createAndFinishSpanForOtelSpan(node, spans, sentSpans) {
|
|
|
1979
1949
|
});
|
|
1980
1950
|
}
|
|
1981
1951
|
|
|
1952
|
+
/**
|
|
1953
|
+
* Get span data from the OTEL span
|
|
1954
|
+
*/
|
|
1982
1955
|
function getSpanData(span)
|
|
1983
1956
|
|
|
1984
1957
|
{
|
|
@@ -2045,6 +2018,66 @@ function getData(span) {
|
|
|
2045
2018
|
return data;
|
|
2046
2019
|
}
|
|
2047
2020
|
|
|
2021
|
+
/**
|
|
2022
|
+
* A Sentry-specific exporter that buffers span JSON objects and streams them to Sentry
|
|
2023
|
+
* in Span v2 envelopes. This exporter works with pre-serialized span JSON rather than
|
|
2024
|
+
* OTel span instances to avoid mutating already-ended spans.
|
|
2025
|
+
*/
|
|
2026
|
+
class StreamingSpanExporter {
|
|
2027
|
+
|
|
2028
|
+
constructor(client, options) {
|
|
2029
|
+
this._client = client;
|
|
2030
|
+
this._buffer = new SpanBuffer(client, {
|
|
2031
|
+
maxSpanLimit: options?.maxSpanLimit,
|
|
2032
|
+
flushInterval: options?.flushInterval,
|
|
2033
|
+
});
|
|
2034
|
+
|
|
2035
|
+
// OTel-specific: add span attributes from ReadableSpan
|
|
2036
|
+
this._client.on('processSpan', (spanJSON, hint) => {
|
|
2037
|
+
const { readOnlySpan } = hint;
|
|
2038
|
+
// TODO: This can be simplified by using spanJSON to get the data instead of the readOnlySpan
|
|
2039
|
+
// for now this is the easiest backwards-compatible way to get the data.
|
|
2040
|
+
const { op, description, data, origin = 'manual' } = getSpanData(readOnlySpan );
|
|
2041
|
+
const allData = {
|
|
2042
|
+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: origin,
|
|
2043
|
+
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: op,
|
|
2044
|
+
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'custom',
|
|
2045
|
+
...data,
|
|
2046
|
+
};
|
|
2047
|
+
safeSetSpanJSONAttributes(spanJSON, allData);
|
|
2048
|
+
spanJSON.name = description;
|
|
2049
|
+
});
|
|
2050
|
+
|
|
2051
|
+
this._client.on('enqueueSpan', spanJSON => {
|
|
2052
|
+
this._buffer.addSpan(spanJSON);
|
|
2053
|
+
});
|
|
2054
|
+
|
|
2055
|
+
DEBUG_BUILD && debug.log('[Tracing] Initialized StreamingSpanExporter');
|
|
2056
|
+
}
|
|
2057
|
+
|
|
2058
|
+
/**
|
|
2059
|
+
* Enqueue a span JSON into the buffer
|
|
2060
|
+
*/
|
|
2061
|
+
export(span) {
|
|
2062
|
+
captureSpan(span, this._client);
|
|
2063
|
+
}
|
|
2064
|
+
|
|
2065
|
+
/**
|
|
2066
|
+
* Try to flush any pending spans immediately.
|
|
2067
|
+
*/
|
|
2068
|
+
flush() {
|
|
2069
|
+
this._buffer.flush();
|
|
2070
|
+
}
|
|
2071
|
+
|
|
2072
|
+
/**
|
|
2073
|
+
* Clear the exporter.
|
|
2074
|
+
* This is called when the span processor is shut down.
|
|
2075
|
+
*/
|
|
2076
|
+
clear() {
|
|
2077
|
+
// No-op for streaming exporter - spans are flushed immediately on interval
|
|
2078
|
+
}
|
|
2079
|
+
}
|
|
2080
|
+
|
|
2048
2081
|
function onSpanStart(span, parentContext) {
|
|
2049
2082
|
// This is a reliable way to get the parent span - because this is exactly how the parent is identified in the OTEL SDK
|
|
2050
2083
|
const parentSpan = trace.getSpan(parentContext);
|
|
@@ -2081,13 +2114,6 @@ function onSpanStart(span, parentContext) {
|
|
|
2081
2114
|
client?.emit('spanStart', span);
|
|
2082
2115
|
}
|
|
2083
2116
|
|
|
2084
|
-
function onSpanEnd(span) {
|
|
2085
|
-
logSpanEnd(span);
|
|
2086
|
-
|
|
2087
|
-
const client = getClient();
|
|
2088
|
-
client?.emit('spanEnd', span);
|
|
2089
|
-
}
|
|
2090
|
-
|
|
2091
2117
|
/**
|
|
2092
2118
|
* Converts OpenTelemetry Spans to Sentry Spans and sends them to Sentry via
|
|
2093
2119
|
* the Sentry SDK.
|
|
@@ -2096,7 +2122,12 @@ class SentrySpanProcessor {
|
|
|
2096
2122
|
|
|
2097
2123
|
constructor(options) {
|
|
2098
2124
|
setIsSetup('SentrySpanProcessor');
|
|
2099
|
-
this.
|
|
2125
|
+
this._client = options?.client ?? getClient();
|
|
2126
|
+
if (this._client?.getOptions().traceLifecycle === 'stream') {
|
|
2127
|
+
this._exporter = new StreamingSpanExporter(this._client, { flushInterval: options?.timeout });
|
|
2128
|
+
} else {
|
|
2129
|
+
this._exporter = new SentrySpanExporter(options);
|
|
2130
|
+
}
|
|
2100
2131
|
}
|
|
2101
2132
|
|
|
2102
2133
|
/**
|
|
@@ -2122,7 +2153,9 @@ class SentrySpanProcessor {
|
|
|
2122
2153
|
|
|
2123
2154
|
/** @inheritDoc */
|
|
2124
2155
|
onEnd(span) {
|
|
2125
|
-
|
|
2156
|
+
logSpanEnd(span);
|
|
2157
|
+
|
|
2158
|
+
this._client?.emit('spanEnd', span);
|
|
2126
2159
|
|
|
2127
2160
|
this._exporter.export(span);
|
|
2128
2161
|
}
|
|
@@ -2360,5 +2393,5 @@ function getValidSpan(context) {
|
|
|
2360
2393
|
return span && isSpanContextValid(span.spanContext()) ? span : undefined;
|
|
2361
2394
|
}
|
|
2362
2395
|
|
|
2363
|
-
export { SEMANTIC_ATTRIBUTE_SENTRY_GRAPHQL_OPERATION, SentryPropagator, SentrySampler, SentrySpanProcessor, continueTrace, enhanceDscWithOpenTelemetryRootSpanName, getActiveSpan, getRequestSpanData, getScopesFromContext, getSpanKind, getTraceContextForScope, isSentryRequestSpan, openTelemetrySetupCheck, setOpenTelemetryContextAsyncContextStrategy, setupEventContextTrace,
|
|
2396
|
+
export { SEMANTIC_ATTRIBUTE_SENTRY_GRAPHQL_OPERATION, SentryPropagator, SentrySampler, SentrySpanProcessor, continueTrace, enhanceDscWithOpenTelemetryRootSpanName, getActiveSpan, getRequestSpanData, getScopesFromContext, getSpanKind, getTraceContextForScope, isSentryRequestSpan, openTelemetrySetupCheck, setOpenTelemetryContextAsyncContextStrategy, setupEventContextTrace, spanHasAttributes, spanHasEvents, spanHasKind, spanHasName, spanHasParentId, spanHasStatus, startInactiveSpan, startSpan, startSpanManual, suppressTracing, withActiveSpan, wrapClientClass, wrapContextManagerClass, wrapSamplingDecision };
|
|
2364
2397
|
//# sourceMappingURL=index.js.map
|