UNPKG

@bracketed/otel-api

Version:

@opentelementery/api but ported to suit modern uses. (2025)

1 lines 3.53 kB
{"version":3,"sources":["../../../src/trace/context-utils.ts"],"names":["SPAN_KEY","getValue","undefined","getSpan","getInstance","active","getActiveSpan","span","setValue","setSpan","deleteValue","deleteSpan","spanContext","NonRecordingSpan","setSpanContext","getSpanContext"],"mappings":"qNA0BMA,IAA4B,+DAO3B,CAAA,CAAA,SAAiC,CACvC,CAAA,CAAA,CAAA,CAAA,OAAgBC,CAAAA,CAAAA,SAA+BC,CAAAA,CAAAA,EAAAA,MADhCC,CAAAA,mBAAAA,CAAAA,CAAAA,CAAAA,oBAQf,CAAA,EAAA,CAAA,OAA0BC,CAAAA,CAAAA,wBAAAA,CAAAA,WAAcC,EAAAA,CAAAA,MADzBC,EAAAA,CAAAA,CAAAA,qCAUT,CAAA,CAAA,SAAmCC,CAAAA,CAAU,CACnD,CAAA,CAAA,CAAA,CAAA,OAAeC,CAAAA,CAAAA,QAAmBD,CACnC,CAFgBE,EAAAA,CAAAA,CAAAA,mBAAAA,CAAAA,CAAAA,CAAAA,SAST,CAAA,CAAA,SAAoC,CAC1C,WAAeC,CAAAA,CAAAA,WADAC,EAAAA,CAAAA,CAAAA,mBAAAA,CAAAA,CAAAA,CAAAA,YAWT,CAAA,CAAA,SAA0CC,CAAAA,CAAwB,CACxE,CAAA,CAAA,CAAA,CAAA,OAAwB,CAAA,CAAA,CAAA,CAAIC,IAAiBD,qCAC9C,CAFgBE,CAAAA,CAAAA,CAAAA,CAAAA,mBAAAA,CAAAA,CAAAA,CAAAA,2BAS+B,CAC9C,CAAA,CAAA,CAAA,CAAA,SAAyBF,CAAAA,CAAAA,EAAAA,WADVG,EAAAA,CAAAA,mBAAAA,CAAAA,CAAAA,CAAAA,gBAAAA,CAAAA","file":"context-utils.cjs","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createContextKey } from '../context/context';\nimport type { Context } from '../context/types';\nimport type { Span } from './span';\nimport type { SpanContext } from './span_context';\nimport { NonRecordingSpan } from './NonRecordingSpan';\nimport { ContextAPI } from '../api/context';\n\n/**\n * span key\n */\nconst SPAN_KEY = createContextKey('OpenTelemetry Context Key SPAN');\n\n/**\n * Return the span if one exists\n *\n * @param context context to get span from\n */\nexport function getSpan(context: Context): Span | undefined {\n\treturn (context.getValue(SPAN_KEY) as Span) || undefined;\n}\n\n/**\n * Gets the span from the current context, if one exists.\n */\nexport function getActiveSpan(): Span | undefined {\n\treturn getSpan(ContextAPI.getInstance().active());\n}\n\n/**\n * Set the span on a context\n *\n * @param context context to use as parent\n * @param span span to set active\n */\nexport function setSpan(context: Context, span: Span): Context {\n\treturn context.setValue(SPAN_KEY, span);\n}\n\n/**\n * Remove current span stored in the context\n *\n * @param context context to delete span from\n */\nexport function deleteSpan(context: Context): Context {\n\treturn context.deleteValue(SPAN_KEY);\n}\n\n/**\n * Wrap span context in a NoopSpan and set as span in a new\n * context\n *\n * @param context context to set active span on\n * @param spanContext span context to be wrapped\n */\nexport function setSpanContext(context: Context, spanContext: SpanContext): Context {\n\treturn setSpan(context, new NonRecordingSpan(spanContext));\n}\n\n/**\n * Get the span context of the span if it exists.\n *\n * @param context context to get values from\n */\nexport function getSpanContext(context: Context): SpanContext | undefined {\n\treturn getSpan(context)?.spanContext();\n}\n"]}