@sentry/opentelemetry 7.105.0 → 8.0.0-alpha.2
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 +8 -14
- package/cjs/asyncContextStrategy.js +87 -19
- package/cjs/asyncContextStrategy.js.map +1 -1
- package/cjs/constants.js +16 -4
- package/cjs/constants.js.map +1 -1
- package/cjs/contextManager.js +42 -15
- package/cjs/contextManager.js.map +1 -1
- package/cjs/custom/client.js +0 -28
- package/cjs/custom/client.js.map +1 -1
- package/cjs/custom/getCurrentHub.js +106 -0
- package/cjs/custom/getCurrentHub.js.map +1 -0
- package/cjs/custom/hub.js +3 -136
- package/cjs/custom/hub.js.map +1 -1
- package/cjs/custom/transaction.js +3 -32
- package/cjs/custom/transaction.js.map +1 -1
- package/cjs/index.js +9 -9
- package/cjs/index.js.map +1 -1
- package/cjs/propagator.js +125 -40
- package/cjs/propagator.js.map +1 -1
- package/cjs/sampler.js +7 -6
- package/cjs/sampler.js.map +1 -1
- package/cjs/semanticAttributes.js +0 -9
- package/cjs/semanticAttributes.js.map +1 -1
- package/cjs/setupEventContextTrace.js +12 -7
- package/cjs/setupEventContextTrace.js.map +1 -1
- package/cjs/spanExporter.js +62 -58
- package/cjs/spanExporter.js.map +1 -1
- package/cjs/spanProcessor.js +16 -18
- package/cjs/spanProcessor.js.map +1 -1
- package/cjs/trace.js +120 -23
- package/cjs/trace.js.map +1 -1
- package/cjs/utils/addOriginToSpan.js +2 -2
- package/cjs/utils/addOriginToSpan.js.map +1 -1
- package/cjs/utils/contextData.js +35 -15
- package/cjs/utils/contextData.js.map +1 -1
- package/cjs/utils/dynamicSamplingContext.js +64 -0
- package/cjs/utils/dynamicSamplingContext.js.map +1 -0
- package/cjs/utils/mapStatus.js +5 -4
- package/cjs/utils/mapStatus.js.map +1 -1
- package/cjs/utils/setupCheck.js +17 -0
- package/cjs/utils/setupCheck.js.map +1 -0
- package/cjs/utils/spanData.js +23 -23
- package/cjs/utils/spanData.js.map +1 -1
- package/esm/asyncContextStrategy.js +89 -18
- package/esm/asyncContextStrategy.js.map +1 -1
- package/esm/constants.js +11 -4
- package/esm/constants.js.map +1 -1
- package/esm/contextManager.js +41 -17
- package/esm/contextManager.js.map +1 -1
- package/esm/custom/client.js +0 -28
- package/esm/custom/client.js.map +1 -1
- package/esm/custom/getCurrentHub.js +101 -0
- package/esm/custom/getCurrentHub.js.map +1 -0
- package/esm/custom/hub.js +4 -133
- package/esm/custom/hub.js.map +1 -1
- package/esm/custom/transaction.js +4 -32
- package/esm/custom/transaction.js.map +1 -1
- package/esm/index.js +7 -5
- package/esm/index.js.map +1 -1
- package/esm/propagator.js +128 -45
- package/esm/propagator.js.map +1 -1
- package/esm/sampler.js +7 -6
- package/esm/sampler.js.map +1 -1
- package/esm/semanticAttributes.js +0 -9
- package/esm/semanticAttributes.js.map +1 -1
- package/esm/setupEventContextTrace.js +14 -9
- package/esm/setupEventContextTrace.js.map +1 -1
- package/esm/spanExporter.js +63 -59
- package/esm/spanExporter.js.map +1 -1
- package/esm/spanProcessor.js +12 -14
- package/esm/spanProcessor.js.map +1 -1
- package/esm/trace.js +122 -26
- package/esm/trace.js.map +1 -1
- package/esm/utils/addOriginToSpan.js +2 -2
- package/esm/utils/addOriginToSpan.js.map +1 -1
- package/esm/utils/contextData.js +33 -15
- package/esm/utils/contextData.js.map +1 -1
- package/esm/utils/dynamicSamplingContext.js +59 -0
- package/esm/utils/dynamicSamplingContext.js.map +1 -0
- package/esm/utils/mapStatus.js +5 -4
- package/esm/utils/mapStatus.js.map +1 -1
- package/esm/utils/setupCheck.js +14 -0
- package/esm/utils/setupCheck.js.map +1 -0
- package/esm/utils/spanData.js +22 -20
- package/esm/utils/spanData.js.map +1 -1
- package/package.json +5 -5
- package/types/asyncContextStrategy.d.ts.map +1 -1
- package/types/constants.d.ts +6 -2
- package/types/constants.d.ts.map +1 -1
- package/types/contextManager.d.ts +1 -1
- package/types/contextManager.d.ts.map +1 -1
- package/types/custom/client.d.ts.map +1 -1
- package/types/custom/getCurrentHub.d.ts +7 -0
- package/types/custom/getCurrentHub.d.ts.map +1 -0
- package/types/custom/hub.d.ts +2 -33
- package/types/custom/hub.d.ts.map +1 -1
- package/types/custom/transaction.d.ts +1 -10
- package/types/custom/transaction.d.ts.map +1 -1
- package/types/index.d.ts +7 -5
- package/types/index.d.ts.map +1 -1
- package/types/propagator.d.ts +11 -2
- package/types/propagator.d.ts.map +1 -1
- package/types/sampler.d.ts.map +1 -1
- package/types/semanticAttributes.d.ts +0 -9
- package/types/semanticAttributes.d.ts.map +1 -1
- package/types/setupEventContextTrace.d.ts.map +1 -1
- package/types/spanExporter.d.ts.map +1 -1
- package/types/spanProcessor.d.ts +1 -5
- package/types/spanProcessor.d.ts.map +1 -1
- package/types/trace.d.ts +14 -3
- package/types/trace.d.ts.map +1 -1
- package/types/types.d.ts +7 -12
- package/types/types.d.ts.map +1 -1
- package/types/utils/addOriginToSpan.d.ts.map +1 -1
- package/types/utils/contextData.d.ts +21 -10
- package/types/utils/contextData.d.ts.map +1 -1
- package/types/utils/dynamicSamplingContext.d.ts +11 -0
- package/types/utils/dynamicSamplingContext.d.ts.map +1 -0
- package/types/utils/mapStatus.d.ts +2 -2
- package/types/utils/mapStatus.d.ts.map +1 -1
- package/types/utils/setupCheck.d.ts +9 -0
- package/types/utils/setupCheck.d.ts.map +1 -0
- package/types/utils/spanData.d.ts +14 -8
- package/types/utils/spanData.d.ts.map +1 -1
- package/types-ts3.8/constants.d.ts +6 -2
- package/types-ts3.8/contextManager.d.ts +1 -1
- package/types-ts3.8/custom/getCurrentHub.d.ts +7 -0
- package/types-ts3.8/custom/hub.d.ts +2 -33
- package/types-ts3.8/custom/transaction.d.ts +1 -10
- package/types-ts3.8/index.d.ts +7 -5
- package/types-ts3.8/propagator.d.ts +11 -2
- package/types-ts3.8/semanticAttributes.d.ts +0 -9
- package/types-ts3.8/spanProcessor.d.ts +1 -5
- package/types-ts3.8/trace.d.ts +14 -3
- package/types-ts3.8/types.d.ts +7 -12
- package/types-ts3.8/utils/contextData.d.ts +21 -10
- package/types-ts3.8/utils/dynamicSamplingContext.d.ts +11 -0
- package/types-ts3.8/utils/mapStatus.d.ts +2 -2
- package/types-ts3.8/utils/setupCheck.d.ts +9 -0
- package/types-ts3.8/utils/spanData.d.ts +14 -8
- package/cjs/custom/scope.js +0 -202
- package/cjs/custom/scope.js.map +0 -1
- package/esm/custom/scope.js +0 -200
- package/esm/custom/scope.js.map +0 -1
- package/types/custom/scope.d.ts +0 -42
- package/types/custom/scope.d.ts.map +0 -1
- package/types-ts3.8/custom/scope.d.ts +0 -42
package/cjs/spanExporter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spanExporter.js","sources":["../../src/spanExporter.ts"],"sourcesContent":["import { SpanKind } from '@opentelemetry/api';\nimport type { ExportResult } from '@opentelemetry/core';\nimport { ExportResultCode } from '@opentelemetry/core';\nimport type { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base';\nimport { SemanticAttributes } from '@opentelemetry/semantic-conventions';\nimport { SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, flush, getCurrentScope } from '@sentry/core';\nimport type { Scope, Span as SentrySpan, SpanOrigin, TransactionSource } from '@sentry/types';\nimport { logger } from '@sentry/utils';\n\nimport { getCurrentHub } from './custom/hub';\nimport type { OpenTelemetryTransaction } from './custom/transaction';\nimport { startTransaction } from './custom/transaction';\nimport { DEBUG_BUILD } from './debug-build';\nimport { InternalSentrySemanticAttributes } from './semanticAttributes';\nimport { convertOtelTimeToSeconds } from './utils/convertOtelTimeToSeconds';\nimport { getRequestSpanData } from './utils/getRequestSpanData';\nimport type { SpanNode } from './utils/groupSpansWithParents';\nimport { groupSpansWithParents } from './utils/groupSpansWithParents';\nimport { mapStatus } from './utils/mapStatus';\nimport { parseSpanDescription } from './utils/parseSpanDescription';\nimport { getSpanFinishScope, getSpanHub, getSpanMetadata, getSpanScope } from './utils/spanData';\n\ntype SpanNodeCompleted = SpanNode & { span: ReadableSpan };\n\n/**\n * A Sentry-specific exporter that converts OpenTelemetry Spans to Sentry Spans & Transactions.\n */\nexport class SentrySpanExporter implements SpanExporter {\n private _finishedSpans: ReadableSpan[];\n private _stopped: boolean;\n\n public constructor() {\n this._stopped = false;\n this._finishedSpans = [];\n }\n\n /** @inheritDoc */\n public export(spans: ReadableSpan[], resultCallback: (result: ExportResult) => void): void {\n if (this._stopped) {\n return resultCallback({\n code: ExportResultCode.FAILED,\n error: new Error('Exporter has been stopped'),\n });\n }\n\n const openSpanCount = this._finishedSpans.length;\n const newSpanCount = spans.length;\n\n this._finishedSpans.push(...spans);\n\n const remainingSpans = maybeSend(this._finishedSpans);\n\n const remainingOpenSpanCount = remainingSpans.length;\n const sentSpanCount = openSpanCount + newSpanCount - remainingOpenSpanCount;\n\n DEBUG_BUILD &&\n logger.log(`SpanExporter exported ${sentSpanCount} spans, ${remainingOpenSpanCount} unsent spans remaining`);\n\n this._finishedSpans = remainingSpans.filter(span => {\n const shouldDrop = shouldCleanupSpan(span, 5 * 60);\n DEBUG_BUILD &&\n shouldDrop &&\n logger.log(\n `SpanExporter dropping span ${span.name} (${\n span.spanContext().spanId\n }) because it is pending for more than 5 minutes.`,\n );\n return !shouldDrop;\n });\n\n resultCallback({ code: ExportResultCode.SUCCESS });\n }\n\n /** @inheritDoc */\n public shutdown(): Promise<void> {\n this._stopped = true;\n this._finishedSpans = [];\n return this.forceFlush();\n }\n\n /** @inheritDoc */\n public async forceFlush(): Promise<void> {\n await flush();\n }\n}\n\n/**\n * Send the given spans, but only if they are part of a finished transaction.\n *\n * Returns the unsent spans.\n * Spans remain unsent when their parent span is not yet finished.\n * This will happen regularly, as child spans are generally finished before their parents.\n * But it _could_ also happen because, for whatever reason, a parent span was lost.\n * In this case, we'll eventually need to clean this up.\n */\nfunction maybeSend(spans: ReadableSpan[]): ReadableSpan[] {\n const grouped = groupSpansWithParents(spans);\n const remaining = new Set(grouped);\n\n const rootNodes = getCompletedRootNodes(grouped);\n\n rootNodes.forEach(root => {\n remaining.delete(root);\n const span = root.span;\n const transaction = createTransactionForOtelSpan(span);\n\n root.children.forEach(child => {\n createAndFinishSpanForOtelSpan(child, transaction, remaining);\n });\n\n // Now finish the transaction, which will send it together with all the spans\n // We make sure to use the finish scope\n const scope = getScopeForTransactionFinish(span);\n transaction.finishWithScope(convertOtelTimeToSeconds(span.endTime), scope);\n });\n\n return Array.from(remaining)\n .map(node => node.span)\n .filter((span): span is ReadableSpan => !!span);\n}\n\nfunction getScopeForTransactionFinish(span: ReadableSpan): Scope {\n // The finish scope should normally always be there (and it is already a clone),\n // but for the sake of type safety we fall back to a clone of the current scope\n const scope = getSpanFinishScope(span) || getCurrentScope().clone();\n scope.setContext('otel', {\n attributes: removeSentryAttributes(span.attributes),\n resource: span.resource.attributes,\n });\n return scope;\n}\n\nfunction getCompletedRootNodes(nodes: SpanNode[]): SpanNodeCompleted[] {\n return nodes.filter((node): node is SpanNodeCompleted => !!node.span && !node.parentNode);\n}\n\nfunction shouldCleanupSpan(span: ReadableSpan, maxStartTimeOffsetSeconds: number): boolean {\n const cutoff = Date.now() / 1000 - maxStartTimeOffsetSeconds;\n return convertOtelTimeToSeconds(span.startTime) < cutoff;\n}\n\nfunction parseSpan(span: ReadableSpan): { op?: string; origin?: SpanOrigin; source?: TransactionSource } {\n const attributes = span.attributes;\n\n const origin = attributes[InternalSentrySemanticAttributes.ORIGIN] as SpanOrigin | undefined;\n const op = attributes[InternalSentrySemanticAttributes.OP] as string | undefined;\n const source = attributes[InternalSentrySemanticAttributes.SOURCE] as TransactionSource | undefined;\n\n return { origin, op, source };\n}\n\nfunction createTransactionForOtelSpan(span: ReadableSpan): OpenTelemetryTransaction {\n const scope = getSpanScope(span);\n const hub = getSpanHub(span) || getCurrentHub();\n const spanContext = span.spanContext();\n const spanId = spanContext.spanId;\n const traceId = spanContext.traceId;\n const parentSpanId = span.parentSpanId;\n\n const parentSampled = span.attributes[InternalSentrySemanticAttributes.PARENT_SAMPLED] as boolean | undefined;\n const dynamicSamplingContext = scope ? scope.getPropagationContext().dsc : undefined;\n\n const { op, description, tags, data, origin, source } = getSpanData(span);\n const metadata = getSpanMetadata(span);\n\n const transaction = startTransaction(hub, {\n spanId,\n traceId,\n parentSpanId,\n parentSampled,\n name: description,\n op,\n instrumenter: 'otel',\n status: mapStatus(span),\n startTimestamp: convertOtelTimeToSeconds(span.startTime),\n metadata: {\n dynamicSamplingContext,\n source,\n sampleRate: span.attributes[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE] as number | undefined,\n ...metadata,\n },\n data: removeSentryAttributes(data),\n origin,\n tags,\n sampled: true,\n }) as OpenTelemetryTransaction;\n\n return transaction;\n}\n\nfunction createAndFinishSpanForOtelSpan(node: SpanNode, sentryParentSpan: SentrySpan, remaining: Set<SpanNode>): void {\n remaining.delete(node);\n const span = node.span;\n\n const shouldDrop = !span;\n\n // If this span should be dropped, we still want to create spans for the children of this\n if (shouldDrop) {\n node.children.forEach(child => {\n createAndFinishSpanForOtelSpan(child, sentryParentSpan, remaining);\n });\n return;\n }\n\n const spanId = span.spanContext().spanId;\n const { attributes } = span;\n\n const { op, description, tags, data, origin } = getSpanData(span);\n const allData = { ...removeSentryAttributes(attributes), ...data };\n\n // eslint-disable-next-line deprecation/deprecation\n const sentrySpan = sentryParentSpan.startChild({\n description,\n op,\n data: allData,\n status: mapStatus(span),\n instrumenter: 'otel',\n startTimestamp: convertOtelTimeToSeconds(span.startTime),\n spanId,\n origin,\n tags,\n });\n\n node.children.forEach(child => {\n createAndFinishSpanForOtelSpan(child, sentrySpan, remaining);\n });\n\n sentrySpan.end(convertOtelTimeToSeconds(span.endTime));\n}\n\nfunction getSpanData(span: ReadableSpan): {\n tags: Record<string, string>;\n data: Record<string, unknown>;\n op?: string;\n description: string;\n source?: TransactionSource;\n origin?: SpanOrigin;\n} {\n const { op: definedOp, source: definedSource, origin } = parseSpan(span);\n const { op: inferredOp, description, source: inferredSource, data: inferredData } = parseSpanDescription(span);\n\n const op = definedOp || inferredOp;\n const source = definedSource || inferredSource;\n\n const tags = getTags(span);\n const data = { ...inferredData, ...getData(span) };\n\n return {\n op,\n description,\n source,\n origin,\n tags,\n data,\n };\n}\n\n/**\n * Remove custom `sentry.` attribtues we do not need to send.\n * These are more carrier attributes we use inside of the SDK, we do not need to send them to the API.\n */\nfunction removeSentryAttributes(data: Record<string, unknown>): Record<string, unknown> {\n const cleanedData = { ...data };\n\n /* eslint-disable @typescript-eslint/no-dynamic-delete */\n delete cleanedData[InternalSentrySemanticAttributes.PARENT_SAMPLED];\n delete cleanedData[InternalSentrySemanticAttributes.ORIGIN];\n delete cleanedData[InternalSentrySemanticAttributes.OP];\n delete cleanedData[InternalSentrySemanticAttributes.SOURCE];\n delete cleanedData[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE];\n /* eslint-enable @typescript-eslint/no-dynamic-delete */\n\n return cleanedData;\n}\n\nfunction getTags(span: ReadableSpan): Record<string, string> {\n const attributes = span.attributes;\n const tags: Record<string, string> = {};\n\n if (attributes[SemanticAttributes.HTTP_STATUS_CODE]) {\n const statusCode = attributes[SemanticAttributes.HTTP_STATUS_CODE] as string | number;\n tags['http.status_code'] = `${statusCode}`;\n }\n\n return tags;\n}\n\nfunction getData(span: ReadableSpan): Record<string, unknown> {\n const attributes = span.attributes;\n const data: Record<string, unknown> = {\n 'otel.kind': SpanKind[span.kind],\n };\n\n if (attributes[SemanticAttributes.HTTP_STATUS_CODE]) {\n const statusCode = attributes[SemanticAttributes.HTTP_STATUS_CODE] as string;\n data['http.response.status_code'] = statusCode;\n }\n\n const requestData = getRequestSpanData(span);\n\n if (requestData.url) {\n data.url = requestData.url;\n }\n\n if (requestData['http.query']) {\n data['http.query'] = requestData['http.query'].slice(1);\n }\n if (requestData['http.fragment']) {\n data['http.fragment'] = requestData['http.fragment'].slice(1);\n }\n\n return data;\n}\n"],"names":["ExportResultCode","DEBUG_BUILD","logger","flush","groupSpansWithParents","convertOtelTimeToSeconds","getSpanFinishScope","getCurrentScope","InternalSentrySemanticAttributes","getSpanScope","hub","getSpanHub","getCurrentHub","getSpanMetadata","transaction","startTransaction","mapStatus","SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE","parseSpanDescription","SemanticAttributes","SpanKind","getRequestSpanData"],"mappings":";;;;;;;;;;;;;;;;;;AAwBA;AACA;AACA;AACO,MAAM,oBAA2C;;AAIxD,GAAS,WAAW,GAAG;AACvB,IAAI,IAAI,CAAC,QAAS,GAAE,KAAK,CAAA;AACzB,IAAI,IAAI,CAAC,cAAe,GAAE,EAAE,CAAA;AAC5B,GAAE;AACF;AACA;AACA,GAAS,MAAM,CAAC,KAAK,EAAkB,cAAc,EAAwC;AAC7F,IAAI,IAAI,IAAI,CAAC,QAAQ,EAAE;AACvB,MAAM,OAAO,cAAc,CAAC;AAC5B,QAAQ,IAAI,EAAEA,qBAAgB,CAAC,MAAM;AACrC,QAAQ,KAAK,EAAE,IAAI,KAAK,CAAC,2BAA2B,CAAC;AACrD,OAAO,CAAC,CAAA;AACR,KAAI;AACJ;AACA,IAAI,MAAM,aAAc,GAAE,IAAI,CAAC,cAAc,CAAC,MAAM,CAAA;AACpD,IAAI,MAAM,YAAA,GAAe,KAAK,CAAC,MAAM,CAAA;AACrC;AACA,IAAI,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAA;AACtC;AACA,IAAI,MAAM,iBAAiB,SAAS,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;AACzD;AACA,IAAI,MAAM,sBAAA,GAAyB,cAAc,CAAC,MAAM,CAAA;AACxD,IAAI,MAAM,aAAc,GAAE,gBAAgB,YAAA,GAAe,sBAAsB,CAAA;AAC/E;AACA,IAAIC,sBAAY;AAChB,MAAMC,YAAM,CAAC,GAAG,CAAC,CAAC,sBAAsB,EAAE,aAAa,CAAC,QAAQ,EAAE,sBAAsB,CAAC,uBAAuB,CAAC,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":"spanExporter.js","sources":["../../src/spanExporter.ts"],"sourcesContent":["import { SpanKind } from '@opentelemetry/api';\nimport type { ExportResult } from '@opentelemetry/core';\nimport { ExportResultCode } from '@opentelemetry/core';\nimport type { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base';\nimport { SemanticAttributes } from '@opentelemetry/semantic-conventions';\nimport type { SentrySpan, Transaction } from '@sentry/core';\nimport {\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n getCurrentHub,\n} from '@sentry/core';\nimport type { Scope, SpanOrigin, TransactionSource } from '@sentry/types';\nimport { addNonEnumerableProperty, dropUndefinedKeys, logger } from '@sentry/utils';\nimport { startTransaction } from './custom/transaction';\n\nimport { DEBUG_BUILD } from './debug-build';\nimport { InternalSentrySemanticAttributes } from './semanticAttributes';\nimport { convertOtelTimeToSeconds } from './utils/convertOtelTimeToSeconds';\nimport { getDynamicSamplingContextFromSpan } from './utils/dynamicSamplingContext';\nimport { getRequestSpanData } from './utils/getRequestSpanData';\nimport type { SpanNode } from './utils/groupSpansWithParents';\nimport { groupSpansWithParents } from './utils/groupSpansWithParents';\nimport { mapStatus } from './utils/mapStatus';\nimport { parseSpanDescription } from './utils/parseSpanDescription';\nimport { getSpanHub, getSpanMetadata, getSpanScopes } from './utils/spanData';\n\ntype SpanNodeCompleted = SpanNode & { span: ReadableSpan };\n\n/**\n * A Sentry-specific exporter that converts OpenTelemetry Spans to Sentry Spans & Transactions.\n */\nexport class SentrySpanExporter implements SpanExporter {\n private _finishedSpans: ReadableSpan[];\n private _stopped: boolean;\n\n public constructor() {\n this._stopped = false;\n this._finishedSpans = [];\n }\n\n /** @inheritDoc */\n public export(spans: ReadableSpan[], resultCallback: (result: ExportResult) => void): void {\n if (this._stopped) {\n return resultCallback({\n code: ExportResultCode.FAILED,\n error: new Error('Exporter has been stopped'),\n });\n }\n\n const openSpanCount = this._finishedSpans.length;\n const newSpanCount = spans.length;\n\n this._finishedSpans.push(...spans);\n\n const remainingSpans = maybeSend(this._finishedSpans);\n\n const remainingOpenSpanCount = remainingSpans.length;\n const sentSpanCount = openSpanCount + newSpanCount - remainingOpenSpanCount;\n\n DEBUG_BUILD &&\n logger.log(`SpanExporter exported ${sentSpanCount} spans, ${remainingOpenSpanCount} unsent spans remaining`);\n\n this._finishedSpans = remainingSpans.filter(span => {\n const shouldDrop = shouldCleanupSpan(span, 5 * 60);\n DEBUG_BUILD &&\n shouldDrop &&\n logger.log(\n `SpanExporter dropping span ${span.name} (${\n span.spanContext().spanId\n }) because it is pending for more than 5 minutes.`,\n );\n return !shouldDrop;\n });\n\n resultCallback({ code: ExportResultCode.SUCCESS });\n }\n\n /** @inheritDoc */\n public shutdown(): Promise<void> {\n const forceFlush = this.forceFlush();\n this._stopped = true;\n this._finishedSpans = [];\n return forceFlush;\n }\n\n /** @inheritDoc */\n public forceFlush(): Promise<void> {\n return new Promise(resolve => {\n this.export(this._finishedSpans, () => resolve());\n });\n }\n}\n\n/**\n * Send the given spans, but only if they are part of a finished transaction.\n *\n * Returns the unsent spans.\n * Spans remain unsent when their parent span is not yet finished.\n * This will happen regularly, as child spans are generally finished before their parents.\n * But it _could_ also happen because, for whatever reason, a parent span was lost.\n * In this case, we'll eventually need to clean this up.\n */\nfunction maybeSend(spans: ReadableSpan[]): ReadableSpan[] {\n const grouped = groupSpansWithParents(spans);\n const remaining = new Set(grouped);\n\n const rootNodes = getCompletedRootNodes(grouped);\n\n rootNodes.forEach(root => {\n remaining.delete(root);\n const span = root.span;\n const transaction = createTransactionForOtelSpan(span);\n\n root.children.forEach(child => {\n createAndFinishSpanForOtelSpan(child, transaction, remaining);\n });\n\n transaction.end(span.endTime);\n });\n\n return Array.from(remaining)\n .map(node => node.span)\n .filter((span): span is ReadableSpan => !!span);\n}\n\nfunction getCompletedRootNodes(nodes: SpanNode[]): SpanNodeCompleted[] {\n return nodes.filter((node): node is SpanNodeCompleted => !!node.span && !node.parentNode);\n}\n\nfunction shouldCleanupSpan(span: ReadableSpan, maxStartTimeOffsetSeconds: number): boolean {\n const cutoff = Date.now() / 1000 - maxStartTimeOffsetSeconds;\n return convertOtelTimeToSeconds(span.startTime) < cutoff;\n}\n\nfunction parseSpan(span: ReadableSpan): { op?: string; origin?: SpanOrigin; source?: TransactionSource } {\n const attributes = span.attributes;\n\n const origin = attributes[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] as SpanOrigin | undefined;\n const op = attributes[SEMANTIC_ATTRIBUTE_SENTRY_OP] as string | undefined;\n const source = attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] as TransactionSource | undefined;\n\n return { origin, op, source };\n}\n\nfunction createTransactionForOtelSpan(span: ReadableSpan): Transaction {\n // eslint-disable-next-line deprecation/deprecation\n const hub = getSpanHub(span) || getCurrentHub();\n const spanContext = span.spanContext();\n const spanId = spanContext.spanId;\n const traceId = spanContext.traceId;\n const parentSpanId = span.parentSpanId;\n\n const parentSampled = span.attributes[InternalSentrySemanticAttributes.PARENT_SAMPLED] as boolean | undefined;\n\n const { op, description, data, origin, source } = getSpanData(span);\n const metadata = getSpanMetadata(span);\n const capturedSpanScopes = getSpanScopes(span);\n\n const sampleRate = span.attributes[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE] as number | undefined;\n\n const attributes = {\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source,\n [SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: sampleRate,\n ...data,\n ...removeSentryAttributes(span.attributes),\n };\n\n const dynamicSamplingContext = getDynamicSamplingContextFromSpan(span);\n\n const transaction = startTransaction(hub, {\n spanId,\n traceId,\n parentSpanId,\n parentSampled,\n name: description,\n op,\n startTimestamp: convertOtelTimeToSeconds(span.startTime),\n metadata: {\n ...dropUndefinedKeys({\n dynamicSamplingContext,\n sampleRate,\n }),\n ...metadata,\n },\n attributes,\n origin,\n sampled: true,\n });\n\n transaction.setStatus(mapStatus(span));\n\n // We currently don't want to write this to the scope because it would mutate it.\n // In the future we will likely have some sort of transaction payload factory where we can pass this context in directly\n // eslint-disable-next-line deprecation/deprecation\n transaction.setContext('otel', {\n attributes: removeSentryAttributes(span.attributes),\n resource: span.resource.attributes,\n });\n\n if (capturedSpanScopes) {\n setCapturedScopesOnTransaction(transaction, capturedSpanScopes.scope, capturedSpanScopes.isolationScope);\n }\n\n return transaction;\n}\n\nfunction createAndFinishSpanForOtelSpan(node: SpanNode, sentryParentSpan: SentrySpan, remaining: Set<SpanNode>): void {\n remaining.delete(node);\n const span = node.span;\n\n const shouldDrop = !span;\n\n // If this span should be dropped, we still want to create spans for the children of this\n if (shouldDrop) {\n node.children.forEach(child => {\n createAndFinishSpanForOtelSpan(child, sentryParentSpan, remaining);\n });\n return;\n }\n\n const spanId = span.spanContext().spanId;\n const { attributes } = span;\n\n const { op, description, data, origin } = getSpanData(span);\n const allData = { ...removeSentryAttributes(attributes), ...data };\n\n // eslint-disable-next-line deprecation/deprecation\n const sentrySpan = sentryParentSpan.startChild({\n name: description,\n op,\n data: allData,\n startTimestamp: convertOtelTimeToSeconds(span.startTime),\n spanId,\n origin,\n }) as SentrySpan;\n sentrySpan.setStatus(mapStatus(span));\n\n node.children.forEach(child => {\n createAndFinishSpanForOtelSpan(child, sentrySpan, remaining);\n });\n\n sentrySpan.end(convertOtelTimeToSeconds(span.endTime));\n}\n\nfunction getSpanData(span: ReadableSpan): {\n data: Record<string, unknown>;\n op?: string;\n description: string;\n source?: TransactionSource;\n origin?: SpanOrigin;\n} {\n const { op: definedOp, source: definedSource, origin } = parseSpan(span);\n const { op: inferredOp, description, source: inferredSource, data: inferredData } = parseSpanDescription(span);\n\n const op = definedOp || inferredOp;\n const source = definedSource || inferredSource;\n\n const data = { ...inferredData, ...getData(span) };\n\n return {\n op,\n description,\n source,\n origin,\n data,\n };\n}\n\n/**\n * Remove custom `sentry.` attribtues we do not need to send.\n * These are more carrier attributes we use inside of the SDK, we do not need to send them to the API.\n */\nfunction removeSentryAttributes(data: Record<string, unknown>): Record<string, unknown> {\n const cleanedData = { ...data };\n\n /* eslint-disable @typescript-eslint/no-dynamic-delete */\n delete cleanedData[InternalSentrySemanticAttributes.PARENT_SAMPLED];\n delete cleanedData[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE];\n /* eslint-enable @typescript-eslint/no-dynamic-delete */\n\n return cleanedData;\n}\n\nfunction getData(span: ReadableSpan): Record<string, unknown> {\n const attributes = span.attributes;\n const data: Record<string, unknown> = {\n 'otel.kind': SpanKind[span.kind],\n };\n\n if (attributes[SemanticAttributes.HTTP_STATUS_CODE]) {\n const statusCode = attributes[SemanticAttributes.HTTP_STATUS_CODE] as string;\n data['http.response.status_code'] = statusCode;\n }\n\n const requestData = getRequestSpanData(span);\n\n if (requestData.url) {\n data.url = requestData.url;\n }\n\n if (requestData['http.query']) {\n data['http.query'] = requestData['http.query'].slice(1);\n }\n if (requestData['http.fragment']) {\n data['http.fragment'] = requestData['http.fragment'].slice(1);\n }\n\n return data;\n}\n\nconst SCOPE_ON_START_SPAN_FIELD = '_sentryScope';\nconst ISOLATION_SCOPE_ON_START_SPAN_FIELD = '_sentryIsolationScope';\n\n/** Sets the scope and isolation scope to be used for when the transaction is finished. */\nfunction setCapturedScopesOnTransaction(span: Transaction, scope: Scope, isolationScope: Scope): void {\n if (span) {\n addNonEnumerableProperty(span, ISOLATION_SCOPE_ON_START_SPAN_FIELD, isolationScope);\n addNonEnumerableProperty(span, SCOPE_ON_START_SPAN_FIELD, scope);\n }\n}\n"],"names":["ExportResultCode","DEBUG_BUILD","logger","groupSpansWithParents","convertOtelTimeToSeconds","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","SEMANTIC_ATTRIBUTE_SENTRY_OP","SEMANTIC_ATTRIBUTE_SENTRY_SOURCE","getSpanHub","getCurrentHub","InternalSentrySemanticAttributes","getSpanMetadata","getSpanScopes","SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE","dynamicSamplingContext","getDynamicSamplingContextFromSpan","transaction","startTransaction","dropUndefinedKeys","mapStatus","parseSpanDescription","SpanKind","SemanticAttributes","getRequestSpanData","addNonEnumerableProperty"],"mappings":";;;;;;;;;;;;;;;;;;AA8BA;AACA;AACA;AACO,MAAM,oBAA2C;;AAIxD,GAAS,WAAW,GAAG;AACvB,IAAI,IAAI,CAAC,QAAS,GAAE,KAAK,CAAA;AACzB,IAAI,IAAI,CAAC,cAAe,GAAE,EAAE,CAAA;AAC5B,GAAE;AACF;AACA;AACA,GAAS,MAAM,CAAC,KAAK,EAAkB,cAAc,EAAwC;AAC7F,IAAI,IAAI,IAAI,CAAC,QAAQ,EAAE;AACvB,MAAM,OAAO,cAAc,CAAC;AAC5B,QAAQ,IAAI,EAAEA,qBAAgB,CAAC,MAAM;AACrC,QAAQ,KAAK,EAAE,IAAI,KAAK,CAAC,2BAA2B,CAAC;AACrD,OAAO,CAAC,CAAA;AACR,KAAI;AACJ;AACA,IAAI,MAAM,aAAc,GAAE,IAAI,CAAC,cAAc,CAAC,MAAM,CAAA;AACpD,IAAI,MAAM,YAAA,GAAe,KAAK,CAAC,MAAM,CAAA;AACrC;AACA,IAAI,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAA;AACtC;AACA,IAAI,MAAM,iBAAiB,SAAS,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;AACzD;AACA,IAAI,MAAM,sBAAA,GAAyB,cAAc,CAAC,MAAM,CAAA;AACxD,IAAI,MAAM,aAAc,GAAE,gBAAgB,YAAA,GAAe,sBAAsB,CAAA;AAC/E;AACA,IAAIC,sBAAY;AAChB,MAAMC,YAAM,CAAC,GAAG,CAAC,CAAC,sBAAsB,EAAE,aAAa,CAAC,QAAQ,EAAE,sBAAsB,CAAC,uBAAuB,CAAC,CAAC,CAAA;AAClH;AACA,IAAI,IAAI,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AAU,CAACA,sCAAkB,CAAC,gBAAgB,CAAE,EAAA;AACvE,IAAI,IAAI,CAAC,2BAA2B,CAAA,GAAI,UAAU,CAAA;AAClD,GAAE;AACF;AACA,EAAE,MAAM,WAAY,GAAEC,qCAAkB,CAAC,IAAI,CAAC,CAAA;AAC9C;AACA,EAAE,IAAI,WAAW,CAAC,GAAG,EAAE;AACvB,IAAI,IAAI,CAAC,GAAA,GAAM,WAAW,CAAC,GAAG,CAAA;AAC9B,GAAE;AACF;AACA,EAAE,IAAI,WAAW,CAAC,YAAY,CAAC,EAAE;AACjC,IAAI,IAAI,CAAC,YAAY,CAAA,GAAI,WAAW,CAAC,YAAY,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AAC3D,GAAE;AACF,EAAE,IAAI,WAAW,CAAC,eAAe,CAAC,EAAE;AACpC,IAAI,IAAI,CAAC,eAAe,CAAA,GAAI,WAAW,CAAC,eAAe,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AACjE,GAAE;AACF;AACA,EAAE,OAAO,IAAI,CAAA;AACb,CAAA;AACA;AACA,MAAM,yBAAA,GAA4B,cAAc,CAAA;AAChD,MAAM,mCAAA,GAAsC,uBAAuB,CAAA;AACnE;AACA;AACA,SAAS,8BAA8B,CAAC,IAAI,EAAe,KAAK,EAAS,cAAc,EAAe;AACtG,EAAE,IAAI,IAAI,EAAE;AACZ,IAAIC,8BAAwB,CAAC,IAAI,EAAE,mCAAmC,EAAE,cAAc,CAAC,CAAA;AACvF,IAAIA,8BAAwB,CAAC,IAAI,EAAE,yBAAyB,EAAE,KAAK,CAAC,CAAA;AACpE,GAAE;AACF;;;;"}
|
package/cjs/spanProcessor.js
CHANGED
|
@@ -2,19 +2,19 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
2
2
|
|
|
3
3
|
const api = require('@opentelemetry/api');
|
|
4
4
|
const sdkTraceBase = require('@opentelemetry/sdk-trace-base');
|
|
5
|
+
const core = require('@sentry/core');
|
|
5
6
|
const utils = require('@sentry/utils');
|
|
6
|
-
const hub = require('./custom/hub.js');
|
|
7
|
-
const scope = require('./custom/scope.js');
|
|
8
7
|
const debugBuild = require('./debug-build.js');
|
|
9
8
|
const spanExporter = require('./spanExporter.js');
|
|
10
9
|
const captureExceptionForTimedEvent = require('./utils/captureExceptionForTimedEvent.js');
|
|
11
10
|
const contextData = require('./utils/contextData.js');
|
|
11
|
+
const setupCheck = require('./utils/setupCheck.js');
|
|
12
12
|
const spanData = require('./utils/spanData.js');
|
|
13
13
|
|
|
14
|
-
function onSpanStart(span, parentContext
|
|
14
|
+
function onSpanStart(span, parentContext) {
|
|
15
15
|
// This is a reliable way to get the parent span - because this is exactly how the parent is identified in the OTEL SDK
|
|
16
16
|
const parentSpan = api.trace.getSpan(parentContext);
|
|
17
|
-
const hub
|
|
17
|
+
const hub = contextData.getHubFromContext(parentContext);
|
|
18
18
|
|
|
19
19
|
// We need access to the parent span in order to be able to move up the span tree for breadcrumbs
|
|
20
20
|
if (parentSpan) {
|
|
@@ -23,30 +23,29 @@ function onSpanStart(span, parentContext, _ScopeClass) {
|
|
|
23
23
|
|
|
24
24
|
// The root context does not have a hub stored, so we check for this specifically
|
|
25
25
|
// We do this instead of just falling back to `getCurrentHub` to avoid attaching the wrong hub
|
|
26
|
-
let actualHub = hub
|
|
26
|
+
let actualHub = hub;
|
|
27
27
|
if (parentContext === api.ROOT_CONTEXT) {
|
|
28
|
-
|
|
28
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
29
|
+
actualHub = core.getCurrentHub();
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
// We need the scope at time of span creation in order to apply it to the event when the span is finished
|
|
32
33
|
if (actualHub) {
|
|
33
34
|
// eslint-disable-next-line deprecation/deprecation
|
|
34
35
|
const scope = actualHub.getScope();
|
|
35
|
-
|
|
36
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
37
|
+
const isolationScope = actualHub.getIsolationScope();
|
|
36
38
|
spanData.setSpanHub(span, actualHub);
|
|
37
|
-
|
|
38
|
-
// Use this scope for finishing the span
|
|
39
|
-
const finishScope = (scope ).clone();
|
|
40
|
-
finishScope.activeSpan = span;
|
|
41
|
-
spanData.setSpanFinishScope(span, finishScope);
|
|
39
|
+
spanData.setSpanScopes(span, { scope, isolationScope });
|
|
42
40
|
}
|
|
43
41
|
}
|
|
44
42
|
|
|
45
43
|
function onSpanEnd(span) {
|
|
46
44
|
// Capture exceptions as events
|
|
47
|
-
|
|
45
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
46
|
+
const hub = spanData.getSpanHub(span) || core.getCurrentHub();
|
|
48
47
|
span.events.forEach(event => {
|
|
49
|
-
captureExceptionForTimedEvent.maybeCaptureExceptionForTimedEvent(hub
|
|
48
|
+
captureExceptionForTimedEvent.maybeCaptureExceptionForTimedEvent(hub, event, span);
|
|
50
49
|
});
|
|
51
50
|
}
|
|
52
51
|
|
|
@@ -55,18 +54,17 @@ function onSpanEnd(span) {
|
|
|
55
54
|
* the Sentry SDK.
|
|
56
55
|
*/
|
|
57
56
|
class SentrySpanProcessor extends sdkTraceBase.BatchSpanProcessor {
|
|
58
|
-
|
|
59
|
-
constructor(options = {}) {
|
|
57
|
+
constructor() {
|
|
60
58
|
super(new spanExporter.SentrySpanExporter());
|
|
61
59
|
|
|
62
|
-
|
|
60
|
+
setupCheck.setIsSetup('SentrySpanProcessor');
|
|
63
61
|
}
|
|
64
62
|
|
|
65
63
|
/**
|
|
66
64
|
* @inheritDoc
|
|
67
65
|
*/
|
|
68
66
|
onStart(span, parentContext) {
|
|
69
|
-
onSpanStart(span, parentContext
|
|
67
|
+
onSpanStart(span, parentContext);
|
|
70
68
|
|
|
71
69
|
debugBuild.DEBUG_BUILD && utils.logger.log(`[Tracing] Starting span "${span.name}" (${span.spanContext().spanId})`);
|
|
72
70
|
|
package/cjs/spanProcessor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spanProcessor.js","sources":["../../src/spanProcessor.ts"],"sourcesContent":["import type { Context } from '@opentelemetry/api';\nimport { ROOT_CONTEXT, trace } from '@opentelemetry/api';\nimport type { Span, SpanProcessor as SpanProcessorInterface } from '@opentelemetry/sdk-trace-base';\nimport { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';\nimport {
|
|
1
|
+
{"version":3,"file":"spanProcessor.js","sources":["../../src/spanProcessor.ts"],"sourcesContent":["import type { Context } from '@opentelemetry/api';\nimport { ROOT_CONTEXT, trace } from '@opentelemetry/api';\nimport type { Span, SpanProcessor as SpanProcessorInterface } from '@opentelemetry/sdk-trace-base';\nimport { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';\nimport { getCurrentHub } from '@sentry/core';\nimport { logger } from '@sentry/utils';\n\nimport { DEBUG_BUILD } from './debug-build';\nimport { SentrySpanExporter } from './spanExporter';\nimport { maybeCaptureExceptionForTimedEvent } from './utils/captureExceptionForTimedEvent';\nimport { getHubFromContext } from './utils/contextData';\nimport { setIsSetup } from './utils/setupCheck';\nimport { getSpanHub, setSpanHub, setSpanParent, setSpanScopes } from './utils/spanData';\n\nfunction onSpanStart(span: Span, parentContext: Context): void {\n // This is a reliable way to get the parent span - because this is exactly how the parent is identified in the OTEL SDK\n const parentSpan = trace.getSpan(parentContext);\n const hub = getHubFromContext(parentContext);\n\n // We need access to the parent span in order to be able to move up the span tree for breadcrumbs\n if (parentSpan) {\n setSpanParent(span, parentSpan);\n }\n\n // The root context does not have a hub stored, so we check for this specifically\n // We do this instead of just falling back to `getCurrentHub` to avoid attaching the wrong hub\n let actualHub = hub;\n if (parentContext === ROOT_CONTEXT) {\n // eslint-disable-next-line deprecation/deprecation\n actualHub = getCurrentHub();\n }\n\n // We need the scope at time of span creation in order to apply it to the event when the span is finished\n if (actualHub) {\n // eslint-disable-next-line deprecation/deprecation\n const scope = actualHub.getScope();\n // eslint-disable-next-line deprecation/deprecation\n const isolationScope = actualHub.getIsolationScope();\n setSpanHub(span, actualHub);\n setSpanScopes(span, { scope, isolationScope });\n }\n}\n\nfunction onSpanEnd(span: Span): void {\n // Capture exceptions as events\n // eslint-disable-next-line deprecation/deprecation\n const hub = getSpanHub(span) || getCurrentHub();\n span.events.forEach(event => {\n maybeCaptureExceptionForTimedEvent(hub, event, span);\n });\n}\n\n/**\n * Converts OpenTelemetry Spans to Sentry Spans and sends them to Sentry via\n * the Sentry SDK.\n */\nexport class SentrySpanProcessor extends BatchSpanProcessor implements SpanProcessorInterface {\n public constructor() {\n super(new SentrySpanExporter());\n\n setIsSetup('SentrySpanProcessor');\n }\n\n /**\n * @inheritDoc\n */\n public onStart(span: Span, parentContext: Context): void {\n onSpanStart(span, parentContext);\n\n DEBUG_BUILD && logger.log(`[Tracing] Starting span \"${span.name}\" (${span.spanContext().spanId})`);\n\n return super.onStart(span, parentContext);\n }\n\n /** @inheritDoc */\n public onEnd(span: Span): void {\n DEBUG_BUILD && logger.log(`[Tracing] Finishing span \"${span.name}\" (${span.spanContext().spanId})`);\n\n if (!this._shouldSendSpanToSentry(span)) {\n // Prevent this being called to super.onEnd(), which would pass this to the span exporter\n return;\n }\n\n onSpanEnd(span);\n\n return super.onEnd(span);\n }\n\n /**\n * You can overwrite this in a sub class to implement custom behavior for dropping spans.\n * If you return `false` here, the span will not be passed to the exporter and thus not be sent.\n */\n protected _shouldSendSpanToSentry(_span: Span): boolean {\n return true;\n }\n}\n"],"names":["trace","getHubFromContext","setSpanParent","ROOT_CONTEXT","getCurrentHub","setSpanHub","setSpanScopes","getSpanHub","maybeCaptureExceptionForTimedEvent","BatchSpanProcessor","SentrySpanExporter","setIsSetup","DEBUG_BUILD","logger"],"mappings":";;;;;;;;;;;;;AAcA,SAAS,WAAW,CAAC,IAAI,EAAQ,aAAa,EAAiB;AAC/D;AACA,EAAE,MAAM,aAAaA,SAAK,CAAC,OAAO,CAAC,aAAa,CAAC,CAAA;AACjD,EAAE,MAAM,GAAI,GAAEC,6BAAiB,CAAC,aAAa,CAAC,CAAA;AAC9C;AACA;AACA,EAA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BAAA,IAAeC,YAAM,CAAC,GAAG,CAAC,CAAC,yBAAyB,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;AACtG;AACA,IAAI,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,aAAa,CAAC,CAAA;AAC7C,GAAE;AACF;AACA;AACA,GAAS,KAAK,CAAC,IAAI,EAAc;AACjC,IAAID,sBAAA,IAAeC,YAAM,CAAC,GAAG,CAAC,CAAC,0BAA0B,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;AACvG;AACA,IAAI,IAAI,CAAC,IAAI,CAAC,uBAAuB,CAAC,IAAI,CAAC,EAAE;AAC7C;AACA,MAAM,OAAM;AACZ,KAAI;AACJ;AACA,IAAI,SAAS,CAAC,IAAI,CAAC,CAAA;AACnB;AACA,IAAI,OAAO,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;AAC5B,GAAE;AACF;AACA;AACA;AACA;AACA;AACA,GAAY,uBAAuB,CAAC,KAAK,EAAiB;AAC1D,IAAI,OAAO,IAAI,CAAA;AACf,GAAE;AACF;;;;"}
|
package/cjs/trace.js
CHANGED
|
@@ -3,8 +3,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
3
3
|
const api = require('@opentelemetry/api');
|
|
4
4
|
const core = require('@opentelemetry/core');
|
|
5
5
|
const core$1 = require('@sentry/core');
|
|
6
|
-
const
|
|
7
|
-
const
|
|
6
|
+
const utils = require('@sentry/utils');
|
|
7
|
+
const constants = require('./constants.js');
|
|
8
|
+
const contextData = require('./utils/contextData.js');
|
|
9
|
+
const dynamicSamplingContext = require('./utils/dynamicSamplingContext.js');
|
|
10
|
+
const getActiveSpan = require('./utils/getActiveSpan.js');
|
|
8
11
|
const spanData = require('./utils/spanData.js');
|
|
9
12
|
|
|
10
13
|
/**
|
|
@@ -16,17 +19,19 @@ const spanData = require('./utils/spanData.js');
|
|
|
16
19
|
*
|
|
17
20
|
* Note that you'll always get a span passed to the callback, it may just be a NonRecordingSpan if the span is not sampled.
|
|
18
21
|
*/
|
|
19
|
-
function startSpan(
|
|
22
|
+
function startSpan(options, callback) {
|
|
20
23
|
const tracer = getTracer();
|
|
21
24
|
|
|
22
|
-
const { name } =
|
|
25
|
+
const { name } = options;
|
|
23
26
|
|
|
24
|
-
const activeCtx =
|
|
25
|
-
const shouldSkipSpan =
|
|
27
|
+
const activeCtx = getContext(options.scope, options.forceTransaction);
|
|
28
|
+
const shouldSkipSpan = options.onlyIfParent && !api.trace.getSpan(activeCtx);
|
|
26
29
|
const ctx = shouldSkipSpan ? core.suppressTracing(activeCtx) : activeCtx;
|
|
27
30
|
|
|
31
|
+
const spanContext = getSpanContext(options);
|
|
32
|
+
|
|
28
33
|
return tracer.startActiveSpan(name, spanContext, ctx, span => {
|
|
29
|
-
_applySentryAttributesToSpan(span,
|
|
34
|
+
_applySentryAttributesToSpan(span, options);
|
|
30
35
|
|
|
31
36
|
return core$1.handleCallbackErrors(
|
|
32
37
|
() => callback(span),
|
|
@@ -47,17 +52,19 @@ function startSpan(spanContext, callback) {
|
|
|
47
52
|
*
|
|
48
53
|
* Note that you'll always get a span passed to the callback, it may just be a NonRecordingSpan if the span is not sampled.
|
|
49
54
|
*/
|
|
50
|
-
function startSpanManual(
|
|
55
|
+
function startSpanManual(options, callback) {
|
|
51
56
|
const tracer = getTracer();
|
|
52
57
|
|
|
53
|
-
const { name } =
|
|
58
|
+
const { name } = options;
|
|
54
59
|
|
|
55
|
-
const activeCtx =
|
|
56
|
-
const shouldSkipSpan =
|
|
60
|
+
const activeCtx = getContext(options.scope, options.forceTransaction);
|
|
61
|
+
const shouldSkipSpan = options.onlyIfParent && !api.trace.getSpan(activeCtx);
|
|
57
62
|
const ctx = shouldSkipSpan ? core.suppressTracing(activeCtx) : activeCtx;
|
|
58
63
|
|
|
64
|
+
const spanContext = getSpanContext(options);
|
|
65
|
+
|
|
59
66
|
return tracer.startActiveSpan(name, spanContext, ctx, span => {
|
|
60
|
-
_applySentryAttributesToSpan(span,
|
|
67
|
+
_applySentryAttributesToSpan(span, options);
|
|
61
68
|
|
|
62
69
|
return core$1.handleCallbackErrors(
|
|
63
70
|
() => callback(span),
|
|
@@ -78,40 +85,57 @@ function startSpanManual(spanContext, callback) {
|
|
|
78
85
|
* or you didn't set `tracesSampleRate` or `tracesSampler`, this function will not generate spans
|
|
79
86
|
* and the `span` returned from the callback will be undefined.
|
|
80
87
|
*/
|
|
81
|
-
function startInactiveSpan(
|
|
88
|
+
function startInactiveSpan(options) {
|
|
82
89
|
const tracer = getTracer();
|
|
83
90
|
|
|
84
|
-
const { name } =
|
|
91
|
+
const { name } = options;
|
|
85
92
|
|
|
86
|
-
const activeCtx =
|
|
87
|
-
const shouldSkipSpan =
|
|
93
|
+
const activeCtx = getContext(options.scope, options.forceTransaction);
|
|
94
|
+
const shouldSkipSpan = options.onlyIfParent && !api.trace.getSpan(activeCtx);
|
|
88
95
|
const ctx = shouldSkipSpan ? core.suppressTracing(activeCtx) : activeCtx;
|
|
89
96
|
|
|
97
|
+
const spanContext = getSpanContext(options);
|
|
98
|
+
|
|
90
99
|
const span = tracer.startSpan(name, spanContext, ctx);
|
|
91
100
|
|
|
92
|
-
_applySentryAttributesToSpan(span,
|
|
101
|
+
_applySentryAttributesToSpan(span, options);
|
|
93
102
|
|
|
94
103
|
return span;
|
|
95
104
|
}
|
|
96
105
|
|
|
106
|
+
/**
|
|
107
|
+
* Forks the current scope and sets the provided span as active span in the context of the provided callback. Can be
|
|
108
|
+
* passed `null` to start an entirely new span tree.
|
|
109
|
+
*
|
|
110
|
+
* @param span Spans started in the context of the provided callback will be children of this span. If `null` is passed,
|
|
111
|
+
* spans started within the callback will not be attached to a parent span.
|
|
112
|
+
* @param callback Execution context in which the provided span will be active. Is passed the newly forked scope.
|
|
113
|
+
* @returns the value returned from the provided callback function.
|
|
114
|
+
*/
|
|
115
|
+
function withActiveSpan(span, callback) {
|
|
116
|
+
const newContextWithActiveSpan = span ? api.trace.setSpan(api.context.active(), span) : api.trace.deleteSpan(api.context.active());
|
|
117
|
+
return api.context.with(newContextWithActiveSpan, () => callback(core$1.getCurrentScope()));
|
|
118
|
+
}
|
|
119
|
+
|
|
97
120
|
function getTracer() {
|
|
98
|
-
const client =
|
|
121
|
+
const client = core$1.getClient();
|
|
99
122
|
return (client && client.tracer) || api.trace.getTracer('@sentry/opentelemetry', core$1.SDK_VERSION);
|
|
100
123
|
}
|
|
101
124
|
|
|
102
|
-
function _applySentryAttributesToSpan(span,
|
|
103
|
-
|
|
125
|
+
function _applySentryAttributesToSpan(span, options) {
|
|
126
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
127
|
+
const { origin, op, source, metadata } = options;
|
|
104
128
|
|
|
105
129
|
if (origin) {
|
|
106
|
-
span.setAttribute(
|
|
130
|
+
span.setAttribute(core$1.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, origin);
|
|
107
131
|
}
|
|
108
132
|
|
|
109
133
|
if (op) {
|
|
110
|
-
span.setAttribute(
|
|
134
|
+
span.setAttribute(core$1.SEMANTIC_ATTRIBUTE_SENTRY_OP, op);
|
|
111
135
|
}
|
|
112
136
|
|
|
113
137
|
if (source) {
|
|
114
|
-
span.setAttribute(
|
|
138
|
+
span.setAttribute(core$1.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, source);
|
|
115
139
|
}
|
|
116
140
|
|
|
117
141
|
if (metadata) {
|
|
@@ -119,7 +143,80 @@ function _applySentryAttributesToSpan(span, spanContext) {
|
|
|
119
143
|
}
|
|
120
144
|
}
|
|
121
145
|
|
|
146
|
+
function getSpanContext(options) {
|
|
147
|
+
const { startTime, attributes, kind } = options;
|
|
148
|
+
|
|
149
|
+
// OTEL expects timestamps in ms, not seconds
|
|
150
|
+
const fixedStartTime = typeof startTime === 'number' ? ensureTimestampInMilliseconds(startTime) : startTime;
|
|
151
|
+
|
|
152
|
+
return {
|
|
153
|
+
attributes,
|
|
154
|
+
kind,
|
|
155
|
+
startTime: fixedStartTime,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function ensureTimestampInMilliseconds(timestamp) {
|
|
160
|
+
const isMs = timestamp < 9999999999;
|
|
161
|
+
return isMs ? timestamp * 1000 : timestamp;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function getContext(scope, forceTransaction) {
|
|
165
|
+
const ctx = getContextForScope(scope);
|
|
166
|
+
|
|
167
|
+
if (!forceTransaction) {
|
|
168
|
+
return ctx;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Else we need to "fix" the context to have no parent span
|
|
172
|
+
const parentSpan = api.trace.getSpan(ctx);
|
|
173
|
+
|
|
174
|
+
// If there is no parent span, all good, nothing to do!
|
|
175
|
+
if (!parentSpan) {
|
|
176
|
+
return ctx;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Else, we need to do two things:
|
|
180
|
+
// 1. Unset the parent span from the context, so we'll create a new root span
|
|
181
|
+
// 2. Ensure the propagation context is correct, so we'll continue from the parent span
|
|
182
|
+
const ctxWithoutSpan = api.trace.deleteSpan(ctx);
|
|
183
|
+
|
|
184
|
+
const { spanId, traceId, traceFlags } = parentSpan.spanContext();
|
|
185
|
+
// eslint-disable-next-line no-bitwise
|
|
186
|
+
const sampled = Boolean(traceFlags & api.TraceFlags.SAMPLED);
|
|
187
|
+
|
|
188
|
+
const rootSpan = getActiveSpan.getRootSpan(parentSpan);
|
|
189
|
+
const dsc = dynamicSamplingContext.getDynamicSamplingContextFromSpan(rootSpan);
|
|
190
|
+
const dscString = utils.dynamicSamplingContextToSentryBaggageHeader(dsc);
|
|
191
|
+
|
|
192
|
+
const traceState = dscString ? new core.TraceState().set(constants.SENTRY_TRACE_STATE_DSC, dscString) : undefined;
|
|
193
|
+
|
|
194
|
+
const spanContext = {
|
|
195
|
+
traceId,
|
|
196
|
+
spanId,
|
|
197
|
+
isRemote: true,
|
|
198
|
+
traceFlags: sampled ? api.TraceFlags.SAMPLED : api.TraceFlags.NONE,
|
|
199
|
+
traceState,
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
const ctxWithSpanContext = api.trace.setSpanContext(ctxWithoutSpan, spanContext);
|
|
203
|
+
|
|
204
|
+
return ctxWithSpanContext;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function getContextForScope(scope) {
|
|
208
|
+
if (scope) {
|
|
209
|
+
const ctx = contextData.getContextFromScope(scope);
|
|
210
|
+
if (ctx) {
|
|
211
|
+
return ctx;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return api.context.active();
|
|
216
|
+
}
|
|
217
|
+
|
|
122
218
|
exports.startInactiveSpan = startInactiveSpan;
|
|
123
219
|
exports.startSpan = startSpan;
|
|
124
220
|
exports.startSpanManual = startSpanManual;
|
|
221
|
+
exports.withActiveSpan = withActiveSpan;
|
|
125
222
|
//# sourceMappingURL=trace.js.map
|
package/cjs/trace.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trace.js","sources":["../../src/trace.ts"],"sourcesContent":["import type { Span, Tracer } from '@opentelemetry/api';\nimport { context } from '@opentelemetry/api';\nimport { SpanStatusCode, trace } from '@opentelemetry/api';\nimport { suppressTracing } from '@opentelemetry/core';\nimport { SDK_VERSION, handleCallbackErrors } from '@sentry/core';\nimport type { Client } from '@sentry/types';\n\nimport { getClient } from './custom/hub';\nimport { InternalSentrySemanticAttributes } from './semanticAttributes';\nimport type { OpenTelemetryClient, OpenTelemetrySpanContext } from './types';\nimport { setSpanMetadata } from './utils/spanData';\n\n/**\n * Wraps a function with a transaction/span and finishes the span after the function is done.\n * The created span is the active span and will be used as parent by other spans created inside the function\n * and can be accessed via `Sentry.getSpan()`, as long as the function is executed while the scope is active.\n *\n * If you want to create a span that is not set as active, use {@link startInactiveSpan}.\n *\n * Note that you'll always get a span passed to the callback, it may just be a NonRecordingSpan if the span is not sampled.\n */\nexport function startSpan<T>(spanContext: OpenTelemetrySpanContext, callback: (span: Span) => T): T {\n const tracer = getTracer();\n\n const { name } = spanContext;\n\n const activeCtx = context.active();\n const shouldSkipSpan = spanContext.onlyIfParent && !trace.getSpan(activeCtx);\n const ctx = shouldSkipSpan ? suppressTracing(activeCtx) : activeCtx;\n\n return tracer.startActiveSpan(name, spanContext, ctx, span => {\n _applySentryAttributesToSpan(span, spanContext);\n\n return handleCallbackErrors(\n () => callback(span),\n () => {\n span.setStatus({ code: SpanStatusCode.ERROR });\n },\n () => span.end(),\n );\n });\n}\n\n/**\n * Similar to `Sentry.startSpan`. Wraps a function with a span, but does not finish the span\n * after the function is done automatically. You'll have to call `span.end()` manually.\n *\n * The created span is the active span and will be used as parent by other spans created inside the function\n * and can be accessed via `Sentry.getActiveSpan()`, as long as the function is executed while the scope is active.\n *\n * Note that you'll always get a span passed to the callback, it may just be a NonRecordingSpan if the span is not sampled.\n */\nexport function startSpanManual<T>(spanContext: OpenTelemetrySpanContext, callback: (span: Span) => T): T {\n const tracer = getTracer();\n\n const { name } = spanContext;\n\n const activeCtx = context.active();\n const shouldSkipSpan = spanContext.onlyIfParent && !trace.getSpan(activeCtx);\n const ctx = shouldSkipSpan ? suppressTracing(activeCtx) : activeCtx;\n\n return tracer.startActiveSpan(name, spanContext, ctx, span => {\n _applySentryAttributesToSpan(span, spanContext);\n\n return handleCallbackErrors(\n () => callback(span),\n () => {\n span.setStatus({ code: SpanStatusCode.ERROR });\n },\n );\n });\n}\n\n/**\n * @deprecated Use {@link startSpan} instead.\n */\nexport const startActiveSpan = startSpan;\n\n/**\n * Creates a span. This span is not set as active, so will not get automatic instrumentation spans\n * as children or be able to be accessed via `Sentry.getSpan()`.\n *\n * If you want to create a span that is set as active, use {@link startSpan}.\n *\n * Note that if you have not enabled tracing extensions via `addTracingExtensions`\n * or you didn't set `tracesSampleRate` or `tracesSampler`, this function will not generate spans\n * and the `span` returned from the callback will be undefined.\n */\nexport function startInactiveSpan(spanContext: OpenTelemetrySpanContext): Span {\n const tracer = getTracer();\n\n const { name } = spanContext;\n\n const activeCtx = context.active();\n const shouldSkipSpan = spanContext.onlyIfParent && !trace.getSpan(activeCtx);\n const ctx = shouldSkipSpan ? suppressTracing(activeCtx) : activeCtx;\n\n const span = tracer.startSpan(name, spanContext, ctx);\n\n _applySentryAttributesToSpan(span, spanContext);\n\n return span;\n}\n\nfunction getTracer(): Tracer {\n const client = getClient<Client & OpenTelemetryClient>();\n return (client && client.tracer) || trace.getTracer('@sentry/opentelemetry', SDK_VERSION);\n}\n\nfunction _applySentryAttributesToSpan(span: Span, spanContext: OpenTelemetrySpanContext): void {\n const { origin, op, source, metadata } = spanContext;\n\n if (origin) {\n span.setAttribute(InternalSentrySemanticAttributes.ORIGIN, origin);\n }\n\n if (op) {\n span.setAttribute(InternalSentrySemanticAttributes.OP, op);\n }\n\n if (source) {\n span.setAttribute(InternalSentrySemanticAttributes.SOURCE, source);\n }\n\n if (metadata) {\n setSpanMetadata(span, metadata);\n }\n}\n"],"names":["context","trace","suppressTracing","handleCallbackErrors","SpanStatusCode","getClient","SDK_VERSION","InternalSentrySemanticAttributes","setSpanMetadata"],"mappings":";;;;;;;;;AAYA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,SAAS,CAAI,WAAW,EAA4B,QAAQ,EAAwB;AACpG,EAAE,MAAM,MAAA,GAAS,SAAS,EAAE,CAAA;AAC5B;AACA,EAAE,MAAM,EAAE,IAAK,EAAA,GAAI,WAAW,CAAA;AAC9B;AACA,EAAE,MAAM,SAAU,GAAEA,WAAO,CAAC,MAAM,EAAE,CAAA;AACpC,EAAE,MAAM,cAAA,GAAiB,WAAW,CAAC,YAAA,IAAgB,CAACC,SAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;AAC9E,EAAE,MAAM,GAAI,GAAE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AI,CAAC,YAAY,CAACC,mDAAgC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AACtE,GAAE;AACF;AACA,EAAE,IAAI,EAAE,EAAE;AACV,IAAI,IAAI,CAAC,YAAY,CAACA,mDAAgC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAA;AAC9D,GAAE;AACF;AACA,EAAE,IAAI,MAAM,EAAE;AACd,IAAI,IAAI,CAAC,YAAY,CAACA,mDAAgC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AACtE,GAAE;AACF;AACA,EAAE,IAAI,QAAQ,EAAE;AAChB,IAAIC,wBAAe,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;AACnC,GAAE;AACF;;;;;;"}
|
|
1
|
+
{"version":3,"file":"trace.js","sources":["../../src/trace.ts"],"sourcesContent":["import type { Context, Span, SpanContext, SpanOptions, Tracer } from '@opentelemetry/api';\nimport { TraceFlags } from '@opentelemetry/api';\nimport { context } from '@opentelemetry/api';\nimport { SpanStatusCode, trace } from '@opentelemetry/api';\nimport { TraceState, suppressTracing } from '@opentelemetry/core';\nimport {\n SDK_VERSION,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n getClient,\n getCurrentScope,\n handleCallbackErrors,\n} from '@sentry/core';\nimport type { Client, Scope } from '@sentry/types';\nimport { dynamicSamplingContextToSentryBaggageHeader } from '@sentry/utils';\nimport { SENTRY_TRACE_STATE_DSC } from './constants';\n\nimport type { OpenTelemetryClient, OpenTelemetrySpanContext } from './types';\nimport { getContextFromScope } from './utils/contextData';\nimport { getDynamicSamplingContextFromSpan } from './utils/dynamicSamplingContext';\nimport { getRootSpan } from './utils/getActiveSpan';\nimport { setSpanMetadata } from './utils/spanData';\n\n/**\n * Wraps a function with a transaction/span and finishes the span after the function is done.\n * The created span is the active span and will be used as parent by other spans created inside the function\n * and can be accessed via `Sentry.getSpan()`, as long as the function is executed while the scope is active.\n *\n * If you want to create a span that is not set as active, use {@link startInactiveSpan}.\n *\n * Note that you'll always get a span passed to the callback, it may just be a NonRecordingSpan if the span is not sampled.\n */\nexport function startSpan<T>(options: OpenTelemetrySpanContext, callback: (span: Span) => T): T {\n const tracer = getTracer();\n\n const { name } = options;\n\n const activeCtx = getContext(options.scope, options.forceTransaction);\n const shouldSkipSpan = options.onlyIfParent && !trace.getSpan(activeCtx);\n const ctx = shouldSkipSpan ? suppressTracing(activeCtx) : activeCtx;\n\n const spanContext = getSpanContext(options);\n\n return tracer.startActiveSpan(name, spanContext, ctx, span => {\n _applySentryAttributesToSpan(span, options);\n\n return handleCallbackErrors(\n () => callback(span),\n () => {\n span.setStatus({ code: SpanStatusCode.ERROR });\n },\n () => span.end(),\n );\n });\n}\n\n/**\n * Similar to `Sentry.startSpan`. Wraps a function with a span, but does not finish the span\n * after the function is done automatically. You'll have to call `span.end()` manually.\n *\n * The created span is the active span and will be used as parent by other spans created inside the function\n * and can be accessed via `Sentry.getActiveSpan()`, as long as the function is executed while the scope is active.\n *\n * Note that you'll always get a span passed to the callback, it may just be a NonRecordingSpan if the span is not sampled.\n */\nexport function startSpanManual<T>(options: OpenTelemetrySpanContext, callback: (span: Span) => T): T {\n const tracer = getTracer();\n\n const { name } = options;\n\n const activeCtx = getContext(options.scope, options.forceTransaction);\n const shouldSkipSpan = options.onlyIfParent && !trace.getSpan(activeCtx);\n const ctx = shouldSkipSpan ? suppressTracing(activeCtx) : activeCtx;\n\n const spanContext = getSpanContext(options);\n\n return tracer.startActiveSpan(name, spanContext, ctx, span => {\n _applySentryAttributesToSpan(span, options);\n\n return handleCallbackErrors(\n () => callback(span),\n () => {\n span.setStatus({ code: SpanStatusCode.ERROR });\n },\n );\n });\n}\n\n/**\n * @deprecated Use {@link startSpan} instead.\n */\nexport const startActiveSpan = startSpan;\n\n/**\n * Creates a span. This span is not set as active, so will not get automatic instrumentation spans\n * as children or be able to be accessed via `Sentry.getSpan()`.\n *\n * If you want to create a span that is set as active, use {@link startSpan}.\n *\n * Note that if you have not enabled tracing extensions via `addTracingExtensions`\n * or you didn't set `tracesSampleRate` or `tracesSampler`, this function will not generate spans\n * and the `span` returned from the callback will be undefined.\n */\nexport function startInactiveSpan(options: OpenTelemetrySpanContext): Span {\n const tracer = getTracer();\n\n const { name } = options;\n\n const activeCtx = getContext(options.scope, options.forceTransaction);\n const shouldSkipSpan = options.onlyIfParent && !trace.getSpan(activeCtx);\n const ctx = shouldSkipSpan ? suppressTracing(activeCtx) : activeCtx;\n\n const spanContext = getSpanContext(options);\n\n const span = tracer.startSpan(name, spanContext, ctx);\n\n _applySentryAttributesToSpan(span, options);\n\n return span;\n}\n\n/**\n * Forks the current scope and sets the provided span as active span in the context of the provided callback. Can be\n * passed `null` to start an entirely new span tree.\n *\n * @param span Spans started in the context of the provided callback will be children of this span. If `null` is passed,\n * spans started within the callback will not be attached to a parent span.\n * @param callback Execution context in which the provided span will be active. Is passed the newly forked scope.\n * @returns the value returned from the provided callback function.\n */\nexport function withActiveSpan<T>(span: Span | null, callback: (scope: Scope) => T): T {\n const newContextWithActiveSpan = span ? trace.setSpan(context.active(), span) : trace.deleteSpan(context.active());\n return context.with(newContextWithActiveSpan, () => callback(getCurrentScope()));\n}\n\nfunction getTracer(): Tracer {\n const client = getClient<Client & OpenTelemetryClient>();\n return (client && client.tracer) || trace.getTracer('@sentry/opentelemetry', SDK_VERSION);\n}\n\nfunction _applySentryAttributesToSpan(span: Span, options: OpenTelemetrySpanContext): void {\n // eslint-disable-next-line deprecation/deprecation\n const { origin, op, source, metadata } = options;\n\n if (origin) {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, origin);\n }\n\n if (op) {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, op);\n }\n\n if (source) {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, source);\n }\n\n if (metadata) {\n setSpanMetadata(span, metadata);\n }\n}\n\nfunction getSpanContext(options: OpenTelemetrySpanContext): SpanOptions {\n const { startTime, attributes, kind } = options;\n\n // OTEL expects timestamps in ms, not seconds\n const fixedStartTime = typeof startTime === 'number' ? ensureTimestampInMilliseconds(startTime) : startTime;\n\n return {\n attributes,\n kind,\n startTime: fixedStartTime,\n };\n}\n\nfunction ensureTimestampInMilliseconds(timestamp: number): number {\n const isMs = timestamp < 9999999999;\n return isMs ? timestamp * 1000 : timestamp;\n}\n\nfunction getContext(scope: Scope | undefined, forceTransaction: boolean | undefined): Context {\n const ctx = getContextForScope(scope);\n\n if (!forceTransaction) {\n return ctx;\n }\n\n // Else we need to \"fix\" the context to have no parent span\n const parentSpan = trace.getSpan(ctx);\n\n // If there is no parent span, all good, nothing to do!\n if (!parentSpan) {\n return ctx;\n }\n\n // Else, we need to do two things:\n // 1. Unset the parent span from the context, so we'll create a new root span\n // 2. Ensure the propagation context is correct, so we'll continue from the parent span\n const ctxWithoutSpan = trace.deleteSpan(ctx);\n\n const { spanId, traceId, traceFlags } = parentSpan.spanContext();\n // eslint-disable-next-line no-bitwise\n const sampled = Boolean(traceFlags & TraceFlags.SAMPLED);\n\n const rootSpan = getRootSpan(parentSpan);\n const dsc = getDynamicSamplingContextFromSpan(rootSpan);\n const dscString = dynamicSamplingContextToSentryBaggageHeader(dsc);\n\n const traceState = dscString ? new TraceState().set(SENTRY_TRACE_STATE_DSC, dscString) : undefined;\n\n const spanContext: SpanContext = {\n traceId,\n spanId,\n isRemote: true,\n traceFlags: sampled ? TraceFlags.SAMPLED : TraceFlags.NONE,\n traceState,\n };\n\n const ctxWithSpanContext = trace.setSpanContext(ctxWithoutSpan, spanContext);\n\n return ctxWithSpanContext;\n}\n\nfunction getContextForScope(scope?: Scope): Context {\n if (scope) {\n const ctx = getContextFromScope(scope);\n if (ctx) {\n return ctx;\n }\n }\n\n return context.active();\n}\n"],"names":["trace","suppressTracing","handleCallbackErrors","SpanStatusCode","context","getCurrentScope","getClient","SDK_VERSION","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","SEMANTIC_ATTRIBUTE_SENTRY_OP","SEMANTIC_ATTRIBUTE_SENTRY_SOURCE","setSpanMetadata","TraceFlags","getRootSpan","getDynamicSamplingContextFromSpan","dynamicSamplingContextToSentryBaggageHeader","TraceState","SENTRY_TRACE_STATE_DSC","getContextFromScope"],"mappings":";;;;;;;;;;;;AAwBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,SAAS,CAAI,OAAO,EAA4B,QAAQ,EAAwB;AAChG,EAAE,MAAM,MAAA,GAAS,SAAS,EAAE,CAAA;AAC5B;AACA,EAAE,MAAM,EAAE,IAAK,EAAA,GAAI,OAAO,CAAA;AAC1B;AACA,EAAE,MAAM,SAAA,GAAY,UAAU,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAA;AACvE,EAAE,MAAM,cAAA,GAAiB,OAAO,CAAC,YAAA,IAAgB,CAACA,SAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;AAC1E,EAAE,MAAM,GAAI,GAAE,cAAe,GAAEC,oBAAe,CAAC,SAAS,CAAE,GAAE,SAAS,CAAA;AACrE;AACA,EAAE,MAAM,WAAY,GAAE,cAAc,CAAC,OAAO,CAAC,CAAA;AAC7C;AACA,EAAE,OAAO,MAAM,CAAC,eAAe,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,IAAA,IAAQ;AAChE,IAAI,4BAA4B,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;AAC/C;AACA,IAAI,OAAOC,2BAAoB;AAC/B,MAAM,MAAM,QAAQ,CAAC,IAAI,CAAC;AAC1B,MAAM,MAAM;AACZ,QAAQ,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAEC,kBAAc,CAAC,KAAM,EAAC,CAAC,CAAA;AACtD,OAAO;AACP,MAAM,MAAM,IAAI,CAAC,GAAG,EAAE;AACtB,KAAK,CAAA;AACL,GAAG,C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ACb,IAAI,MAAM,GAAI,GAAEkB,+BAAmB,CAAC,KAAK,CAAC,CAAA;AAC1C,IAAI,IAAI,GAAG,EAAE;AACb,MAAM,OAAO,GAAG,CAAA;AAChB,KAAI;AACJ,GAAE;AACF;AACA,EAAE,OAAOd,WAAO,CAAC,MAAM,EAAE,CAAA;AACzB;;;;;;;"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const core = require('@sentry/core');
|
|
4
4
|
|
|
5
5
|
/** Adds an origin to an OTEL Span. */
|
|
6
6
|
function addOriginToSpan(span, origin) {
|
|
7
|
-
span.setAttribute(
|
|
7
|
+
span.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, origin);
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
exports.addOriginToSpan = addOriginToSpan;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addOriginToSpan.js","sources":["../../../src/utils/addOriginToSpan.ts"],"sourcesContent":["import type { Span } from '@opentelemetry/api';\nimport
|
|
1
|
+
{"version":3,"file":"addOriginToSpan.js","sources":["../../../src/utils/addOriginToSpan.ts"],"sourcesContent":["import type { Span } from '@opentelemetry/api';\nimport { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/core';\nimport type { SpanOrigin } from '@sentry/types';\n\n/** Adds an origin to an OTEL Span. */\nexport function addOriginToSpan(span: Span, origin: SpanOrigin): void {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, origin);\n}\n"],"names":["SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN"],"mappings":";;;;AAIA;AACO,SAAS,eAAe,CAAC,IAAI,EAAQ,MAAM,EAAoB;AACtE,EAAE,IAAI,CAAC,YAAY,CAACA,qCAAgC,EAAE,MAAM,CAAC,CAAA;AAC7D;;;;"}
|
package/cjs/utils/contextData.js
CHANGED
|
@@ -2,40 +2,60 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
2
2
|
|
|
3
3
|
const constants = require('../constants.js');
|
|
4
4
|
|
|
5
|
+
const SCOPE_CONTEXT_MAP = new WeakMap();
|
|
6
|
+
|
|
5
7
|
/**
|
|
6
|
-
* Try to get the
|
|
7
|
-
* This requires
|
|
8
|
+
* Try to get the Hub from the given OTEL context.
|
|
9
|
+
* This requires a Context Manager that was wrapped with getWrappedContextManager.
|
|
8
10
|
*/
|
|
9
|
-
function
|
|
10
|
-
return context.getValue(constants.
|
|
11
|
+
function getHubFromContext(context) {
|
|
12
|
+
return context.getValue(constants.SENTRY_HUB_CONTEXT_KEY) ;
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
/**
|
|
14
|
-
* Set a
|
|
16
|
+
* Set a Hub on an OTEL context..
|
|
15
17
|
* This will return a forked context with the Propagation Context set.
|
|
16
18
|
*/
|
|
17
|
-
function
|
|
18
|
-
return context.setValue(constants.
|
|
19
|
+
function setHubOnContext(context, hub) {
|
|
20
|
+
return context.setValue(constants.SENTRY_HUB_CONTEXT_KEY, hub);
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
/**
|
|
22
|
-
* Try to get the
|
|
24
|
+
* Try to get the current scopes from the given OTEL context.
|
|
23
25
|
* This requires a Context Manager that was wrapped with getWrappedContextManager.
|
|
24
26
|
*/
|
|
25
|
-
function
|
|
26
|
-
return context.getValue(constants.
|
|
27
|
+
function getScopesFromContext(context) {
|
|
28
|
+
return context.getValue(constants.SENTRY_SCOPES_CONTEXT_KEY) ;
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
/**
|
|
30
|
-
* Set
|
|
32
|
+
* Set the current scopes on an OTEL context.
|
|
31
33
|
* This will return a forked context with the Propagation Context set.
|
|
32
34
|
*/
|
|
33
|
-
function
|
|
34
|
-
return context.setValue(constants.
|
|
35
|
+
function setScopesOnContext(context, scopes) {
|
|
36
|
+
return context.setValue(constants.SENTRY_SCOPES_CONTEXT_KEY, scopes);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Set the context on the scope so we can later look it up.
|
|
41
|
+
* We need this to get the context from the scope in the `trace` functions.
|
|
42
|
+
*/
|
|
43
|
+
function setContextOnScope(scope, context) {
|
|
44
|
+
SCOPE_CONTEXT_MAP.set(scope, context);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Get the context related to a scope.
|
|
49
|
+
* TODO v8: Use this for the `trace` functions.
|
|
50
|
+
* */
|
|
51
|
+
function getContextFromScope(scope) {
|
|
52
|
+
return SCOPE_CONTEXT_MAP.get(scope);
|
|
35
53
|
}
|
|
36
54
|
|
|
55
|
+
exports.getContextFromScope = getContextFromScope;
|
|
37
56
|
exports.getHubFromContext = getHubFromContext;
|
|
38
|
-
exports.
|
|
57
|
+
exports.getScopesFromContext = getScopesFromContext;
|
|
58
|
+
exports.setContextOnScope = setContextOnScope;
|
|
39
59
|
exports.setHubOnContext = setHubOnContext;
|
|
40
|
-
exports.
|
|
60
|
+
exports.setScopesOnContext = setScopesOnContext;
|
|
41
61
|
//# sourceMappingURL=contextData.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contextData.js","sources":["../../../src/utils/contextData.ts"],"sourcesContent":["import type { Context } from '@opentelemetry/api';\nimport type { Hub,
|
|
1
|
+
{"version":3,"file":"contextData.js","sources":["../../../src/utils/contextData.ts"],"sourcesContent":["import type { Context } from '@opentelemetry/api';\nimport type { Hub, Scope } from '@sentry/types';\n\nimport { SENTRY_HUB_CONTEXT_KEY, SENTRY_SCOPES_CONTEXT_KEY } from '../constants';\nimport type { CurrentScopes } from '../types';\n\nconst SCOPE_CONTEXT_MAP = new WeakMap<Scope, Context>();\n\n/**\n * Try to get the Hub from the given OTEL context.\n * This requires a Context Manager that was wrapped with getWrappedContextManager.\n */\nexport function getHubFromContext(context: Context): Hub | undefined {\n return context.getValue(SENTRY_HUB_CONTEXT_KEY) as Hub | undefined;\n}\n\n/**\n * Set a Hub on an OTEL context..\n * This will return a forked context with the Propagation Context set.\n */\nexport function setHubOnContext(context: Context, hub: Hub): Context {\n return context.setValue(SENTRY_HUB_CONTEXT_KEY, hub);\n}\n\n/**\n * Try to get the current scopes from the given OTEL context.\n * This requires a Context Manager that was wrapped with getWrappedContextManager.\n */\nexport function getScopesFromContext(context: Context): CurrentScopes | undefined {\n return context.getValue(SENTRY_SCOPES_CONTEXT_KEY) as CurrentScopes | undefined;\n}\n\n/**\n * Set the current scopes on an OTEL context.\n * This will return a forked context with the Propagation Context set.\n */\nexport function setScopesOnContext(context: Context, scopes: CurrentScopes): Context {\n return context.setValue(SENTRY_SCOPES_CONTEXT_KEY, scopes);\n}\n\n/**\n * Set the context on the scope so we can later look it up.\n * We need this to get the context from the scope in the `trace` functions.\n */\nexport function setContextOnScope(scope: Scope, context: Context): void {\n SCOPE_CONTEXT_MAP.set(scope, context);\n}\n\n/**\n * Get the context related to a scope.\n * TODO v8: Use this for the `trace` functions.\n * */\nexport function getContextFromScope(scope: Scope): Context | undefined {\n return SCOPE_CONTEXT_MAP.get(scope);\n}\n"],"names":["SENTRY_HUB_CONTEXT_KEY","SENTRY_SCOPES_CONTEXT_KEY"],"mappings":";;;;AAMA,MAAM,iBAAkB,GAAE,IAAI,OAAO,EAAkB,CAAA;AACvD;AACA;AACA;AACA;AACA;AACO,SAAS,iBAAiB,CAAC,OAAO,EAA4B;AACrE,EAAE,OAAO,OAAO,CAAC,QAAQ,CAACA,gCAAsB,CAAE,EAAA;AAClD,CAAA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,eAAe,CAAC,OAAO,EAAW,GAAG,EAAgB;AACrE,EAAE,OAAO,OAAO,CAAC,QAAQ,CAACA,gCAAsB,EAAE,GAAG,CAAC,CAAA;AACtD,CAAA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,oBAAoB,CAAC,OAAO,EAAsC;AAClF,EAAE,OAAO,OAAO,CAAC,QAAQ,CAACC,mCAAyB,CAAE,EAAA;AACrD,CAAA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,kBAAkB,CAAC,OAAO,EAAW,MAAM,EAA0B;AACrF,EAAE,OAAO,OAAO,CAAC,QAAQ,CAACA,mCAAyB,EAAE,MAAM,CAAC,CAAA;AAC5D,CAAA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,iBAAiB,CAAC,KAAK,EAAS,OAAO,EAAiB;AACxE,EAAE,iBAAiB,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;AACvC,CAAA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,mBAAmB,CAAC,KAAK,EAA8B;AACvE,EAAE,OAAO,iBAAiB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;AACrC;;;;;;;;;"}
|