@azure/core-tracing 1.0.0-preview.9 → 1.0.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.
Files changed (40) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/README.md +18 -71
  3. package/dist/index.js +147 -606
  4. package/dist/index.js.map +1 -1
  5. package/dist-esm/src/index.js +2 -10
  6. package/dist-esm/src/index.js.map +1 -1
  7. package/dist-esm/src/instrumenter.js +61 -0
  8. package/dist-esm/src/instrumenter.js.map +1 -0
  9. package/dist-esm/src/interfaces.js +1 -0
  10. package/dist-esm/src/interfaces.js.map +1 -1
  11. package/dist-esm/src/tracingClient.js +74 -0
  12. package/dist-esm/src/tracingClient.js.map +1 -0
  13. package/dist-esm/src/tracingContext.js +52 -0
  14. package/dist-esm/src/tracingContext.js.map +1 -0
  15. package/package.json +49 -46
  16. package/types/core-tracing.d.ts +197 -345
  17. package/dist-esm/src/tracerProxy.js +0 -31
  18. package/dist-esm/src/tracerProxy.js.map +0 -1
  19. package/dist-esm/src/tracers/noop/noOpSpan.js +0 -74
  20. package/dist-esm/src/tracers/noop/noOpSpan.js.map +0 -1
  21. package/dist-esm/src/tracers/noop/noOpTracer.js +0 -44
  22. package/dist-esm/src/tracers/noop/noOpTracer.js.map +0 -1
  23. package/dist-esm/src/tracers/opencensus/openCensusSpanWrapper.js +0 -113
  24. package/dist-esm/src/tracers/opencensus/openCensusSpanWrapper.js.map +0 -1
  25. package/dist-esm/src/tracers/opencensus/openCensusTraceStateWrapper.js +0 -26
  26. package/dist-esm/src/tracers/opencensus/openCensusTraceStateWrapper.js.map +0 -1
  27. package/dist-esm/src/tracers/opencensus/openCensusTracerWrapper.js +0 -54
  28. package/dist-esm/src/tracers/opencensus/openCensusTracerWrapper.js.map +0 -1
  29. package/dist-esm/src/tracers/test/testSpan.js +0 -93
  30. package/dist-esm/src/tracers/test/testSpan.js.map +0 -1
  31. package/dist-esm/src/tracers/test/testTracer.js +0 -127
  32. package/dist-esm/src/tracers/test/testTracer.js.map +0 -1
  33. package/dist-esm/src/utils/cache.js +0 -43
  34. package/dist-esm/src/utils/cache.js.map +0 -1
  35. package/dist-esm/src/utils/global.browser.js +0 -6
  36. package/dist-esm/src/utils/global.browser.js.map +0 -1
  37. package/dist-esm/src/utils/global.js +0 -6
  38. package/dist-esm/src/utils/global.js.map +0 -1
  39. package/dist-esm/src/utils/traceParentHeader.js +0 -48
  40. package/dist-esm/src/utils/traceParentHeader.js.map +0 -1
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/tracers/noop/noOpSpan.ts","../src/tracers/noop/noOpTracer.ts","../src/utils/global.ts","../src/utils/cache.ts","../src/tracerProxy.ts","../src/tracers/opencensus/openCensusTraceStateWrapper.ts","../src/tracers/opencensus/openCensusSpanWrapper.ts","../src/tracers/opencensus/openCensusTracerWrapper.ts","../src/tracers/test/testSpan.ts","../src/tracers/test/testTracer.ts","../src/utils/traceParentHeader.ts"],"sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { Span, SpanContext, Attributes, Status, TraceFlags } from \"@opentelemetry/api\";\n\n/**\n * A no-op implementation of Span that can safely be used without side-effects.\n */\nexport class NoOpSpan implements Span {\n /**\n * Returns the SpanContext associated with this Span.\n */\n context(): SpanContext {\n return {\n spanId: \"\",\n traceId: \"\",\n traceFlags: TraceFlags.NONE\n };\n }\n\n /**\n * Marks the end of Span execution.\n * @param _endTime The time to use as the Span's end time. Defaults to\n * the current time.\n */\n end(_endTime?: number): void {\n /* Noop */\n }\n\n /**\n * Sets an attribute on the Span\n * @param _key the attribute key\n * @param _value the attribute value\n */\n setAttribute(_key: string, _value: unknown): this {\n return this;\n }\n\n /**\n * Sets attributes on the Span\n * @param _attributes the attributes to add\n */\n setAttributes(_attributes: Attributes): this {\n return this;\n }\n\n /**\n * Adds an event to the Span\n * @param _name The name of the event\n * @param _attributes The associated attributes to add for this event\n */\n addEvent(_name: string, _attributes?: Attributes): this {\n return this;\n }\n\n /**\n * Sets a status on the span. Overrides the default of CanonicalCode.OK.\n * @param _status The status to set.\n */\n setStatus(_status: Status): this {\n return this;\n }\n\n /**\n * Updates the name of the Span\n * @param _name the new Span name\n */\n updateName(_name: string): this {\n return this;\n }\n\n /**\n * Returns whether this span will be recorded\n */\n isRecording(): boolean {\n return false;\n }\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { NoOpSpan } from \"./noOpSpan\";\nimport { Tracer, Span, SpanOptions } from \"@opentelemetry/api\";\n\n/**\n * A no-op implementation of Tracer that can be used when tracing\n * is disabled.\n */\nexport class NoOpTracer implements Tracer {\n /**\n * Starts a new Span.\n * @param _name The name of the span.\n * @param _options The SpanOptions used during Span creation.\n */\n startSpan(_name: string, _options?: SpanOptions): Span {\n return new NoOpSpan();\n }\n\n /**\n * Returns the current Span from the current context, if available.\n */\n getCurrentSpan(): Span {\n return new NoOpSpan();\n }\n\n /**\n * Executes the given function within the context provided by a Span.\n * @param _span The span that provides the context.\n * @param fn The function to be executed.\n */\n withSpan<T extends (...args: unknown[]) => ReturnType<T>>(_span: Span, fn: T): ReturnType<T> {\n return fn();\n }\n\n /**\n * Bind a Span as the target's scope\n * @param target An object to bind the scope.\n * @param _span A specific Span to use. Otherwise, use the current one.\n */\n bind<T>(target: T, _span?: Span): T {\n return target;\n }\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nexport function getGlobalObject(): any {\n return global;\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { Tracer } from \"@opentelemetry/api\";\nimport { getGlobalObject } from \"./global\";\n\n// V1 = OpenTelemetry 0.1\n// V2 = OpenTelemetry 0.2\n// V3 = OpenTelemetry 0.6.1\nconst GLOBAL_TRACER_VERSION = 3;\n// preview5 shipped with @azure/core-tracing.tracerCache\n// and didn't have smart detection for collisions\nconst GLOBAL_TRACER_SYMBOL = Symbol.for(\"@azure/core-tracing.tracerCache2\");\n\nexport interface TracerCache {\n version: number;\n tracer?: Tracer;\n}\n\nlet cache: TracerCache;\n\nfunction loadTracerCache(): void {\n const globalObj = getGlobalObject();\n const existingCache: TracerCache = globalObj[GLOBAL_TRACER_SYMBOL];\n let setGlobalCache = true;\n if (existingCache) {\n if (existingCache.version === GLOBAL_TRACER_VERSION) {\n cache = existingCache;\n } else {\n setGlobalCache = false;\n if (existingCache.tracer) {\n throw new Error(\n `Two incompatible versions of @azure/core-tracing have been loaded.\n This library is ${GLOBAL_TRACER_VERSION}, existing is ${existingCache.version}.`\n );\n }\n }\n }\n\n if (!cache) {\n cache = {\n tracer: undefined,\n version: GLOBAL_TRACER_VERSION\n };\n }\n if (setGlobalCache) {\n globalObj[GLOBAL_TRACER_SYMBOL] = cache;\n }\n}\n\nexport function getCache(): TracerCache {\n if (!cache) {\n loadTracerCache();\n }\n return cache;\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { NoOpTracer } from \"./tracers/noop/noOpTracer\";\nimport { Tracer } from \"@opentelemetry/api\";\nimport { getCache } from \"./utils/cache\";\n\nlet defaultTracer: Tracer;\n\nfunction getDefaultTracer(): Tracer {\n if (!defaultTracer) {\n defaultTracer = new NoOpTracer();\n }\n return defaultTracer;\n}\n\n/**\n * Sets the global tracer, enabling tracing for the Azure SDK.\n * @param tracer An OpenTelemetry Tracer instance.\n */\nexport function setTracer(tracer: Tracer): void {\n const cache = getCache();\n cache.tracer = tracer;\n}\n\n/**\n * Retrieves the active tracer, or returns a\n * no-op implementation if one is not set.\n */\nexport function getTracer(): Tracer {\n const cache = getCache();\n if (!cache.tracer) {\n return getDefaultTracer();\n }\n return cache.tracer;\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { TraceState } from \"@opentelemetry/api\";\n\n/**\n * @ignore\n * @internal\n */\nexport class OpenCensusTraceStateWrapper implements TraceState {\n private readonly _state?: string;\n\n constructor(state?: string) {\n this._state = state;\n }\n\n get(_key: string): string | undefined {\n throw new Error(\"Method not implemented.\");\n }\n\n set(_key: string, _value: string): void {\n throw new Error(\"Method not implemented.\");\n }\n\n unset(_key: string): void {\n throw new Error(\"Method not implemented\");\n }\n\n serialize(): string {\n return this._state || \"\";\n }\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { SpanContext, Span, SpanOptions, Attributes, Status, TraceFlags } from \"@opentelemetry/api\";\nimport { OpenCensusTraceStateWrapper } from \"./openCensusTraceStateWrapper\";\nimport { OpenCensusTracerWrapper } from \"./openCensusTracerWrapper\";\nimport { Attributes as OpenCensusAttributes, Span as OpenCensusSpan } from \"@opencensus/web-types\";\n\nfunction isWrappedSpan(span?: Span | SpanContext | null): span is OpenCensusSpanWrapper {\n return !!span && (span as OpenCensusSpanWrapper).getWrappedSpan !== undefined;\n}\n\nfunction isTracer(\n tracerOrSpan: OpenCensusTracerWrapper | OpenCensusSpan\n): tracerOrSpan is OpenCensusTracerWrapper {\n return (tracerOrSpan as OpenCensusTracerWrapper).getWrappedTracer !== undefined;\n}\n\n/**\n * An implementation of OpenTelemetry Span that wraps an OpenCensus Span.\n */\nexport class OpenCensusSpanWrapper implements Span {\n private _span: OpenCensusSpan;\n\n /**\n * The underlying OpenCensus Span\n */\n public getWrappedSpan(): OpenCensusSpan {\n return this._span;\n }\n\n /**\n * Wraps an existing OpenCensus Span\n * @param span A Span or RootSpan from OpenCensus\n */\n constructor(span: OpenCensusSpan);\n /**\n * Create a new OpenCensus Span and wrap it.\n * @param tracer The OpenCensus tracer that has been wrapped in OpenCensusTracerWrapper\n * @param name The name of the Span\n * @param options Options for the Span\n */\n constructor(tracer: OpenCensusTracerWrapper, name: string, options?: SpanOptions);\n constructor(\n tracerOrSpan: OpenCensusTracerWrapper | OpenCensusSpan,\n name: string = \"\",\n options: SpanOptions = {}\n ) {\n if (isTracer(tracerOrSpan)) {\n const parent = isWrappedSpan(options.parent) ? options.parent.getWrappedSpan() : undefined;\n this._span = tracerOrSpan.getWrappedTracer().startChildSpan({\n name,\n childOf: parent\n });\n this._span.start();\n if (options.links) {\n for (const link of options.links) {\n // Since there is no way to set the link relationship, leave it as Unspecified.\n this._span.addLink(\n link.context.traceId,\n link.context.spanId,\n 0 /* LinkType.UNSPECIFIED */,\n link.attributes as OpenCensusAttributes\n );\n }\n }\n } else {\n this._span = tracerOrSpan;\n }\n }\n\n /**\n * Marks the end of Span execution.\n * @param endTime The time to use as the Span's end time. Defaults to\n * the current time.\n */\n end(_endTime?: number): void {\n this._span.end();\n }\n\n /**\n * Returns the SpanContext associated with this Span.\n */\n context(): SpanContext {\n const openCensusSpanContext = this._span.spanContext;\n\n return {\n spanId: openCensusSpanContext.spanId,\n traceId: openCensusSpanContext.traceId,\n traceFlags: openCensusSpanContext.options as TraceFlags,\n traceState: new OpenCensusTraceStateWrapper(openCensusSpanContext.traceState)\n };\n }\n\n /**\n * Sets an attribute on the Span\n * @param key the attribute key\n * @param value the attribute value\n */\n setAttribute(key: string, value: unknown): this {\n this._span.addAttribute(key, value as any);\n return this;\n }\n\n /**\n * Sets attributes on the Span\n * @param attributes the attributes to add\n */\n setAttributes(attributes: Attributes): this {\n this._span.attributes = attributes as OpenCensusAttributes;\n return this;\n }\n\n /**\n * Adds an event to the Span\n * @param name The name of the event\n * @param attributes The associated attributes to add for this event\n */\n addEvent(_name: string, _attributes?: Attributes): this {\n throw new Error(\"Method not implemented.\");\n }\n\n /**\n * Sets a status on the span. Overrides the default of CanonicalCode.OK.\n * @param status The status to set.\n */\n setStatus(status: Status): this {\n this._span.setStatus(status.code, status.message);\n return this;\n }\n\n /**\n * Updates the name of the Span\n * @param name the new Span name\n */\n updateName(name: string): this {\n this._span.name = name;\n return this;\n }\n\n /**\n * Returns whether this span will be recorded\n */\n isRecording(): boolean {\n // NoRecordSpans have an empty traceId\n return !!this._span.traceId;\n }\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { Tracer, Span, SpanOptions } from \"@opentelemetry/api\";\nimport { OpenCensusSpanWrapper } from \"./openCensusSpanWrapper\";\nimport { TracerBase as OpenCensusTracer } from \"@opencensus/web-types\";\n\n/**\n * An implementation of OpenTelemetry Tracer that wraps an OpenCensus Tracer.\n */\nexport class OpenCensusTracerWrapper implements Tracer {\n private _tracer: OpenCensusTracer;\n\n /**\n * The wrapped OpenCensus Tracer\n */\n public getWrappedTracer(): OpenCensusTracer {\n return this._tracer;\n }\n\n /**\n * Create a new wrapper around a given OpenCensus Tracer.\n * @param tracer The OpenCensus Tracer to wrap.\n */\n public constructor(tracer: OpenCensusTracer) {\n this._tracer = tracer;\n }\n\n /**\n * Starts a new Span.\n * @param name The name of the span.\n * @param options The SpanOptions used during Span creation.\n */\n startSpan(name: string, options?: SpanOptions): Span {\n return new OpenCensusSpanWrapper(this, name, options);\n }\n\n /**\n * Returns the current Span from the current context, if available.\n */\n getCurrentSpan(): Span | undefined {\n return undefined;\n }\n\n /**\n * Executes the given function within the context provided by a Span.\n * @param _span The span that provides the context.\n * @param _fn The function to be executed.\n */\n withSpan<T extends (...args: unknown[]) => unknown>(_span: Span, _fn: T): ReturnType<T> {\n throw new Error(\"Method not implemented.\");\n }\n\n /**\n * Bind a Span as the target's scope\n * @param target An object to bind the scope.\n * @param _span A specific Span to use. Otherwise, use the current one.\n */\n bind<T>(_target: T, _span?: Span): T {\n throw new Error(\"Method not implemented.\");\n }\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n TimeInput,\n Tracer,\n SpanKind,\n Status,\n SpanContext,\n CanonicalCode,\n Attributes\n} from \"@opentelemetry/api\";\nimport { NoOpSpan } from \"../noop/noOpSpan\";\n\n/**\n * A mock span useful for testing.\n */\nexport class TestSpan extends NoOpSpan {\n /**\n * The Span's current name\n */\n name: string;\n\n /**\n * The Span's current status\n */\n status: Status;\n\n /**\n * The Span's kind\n */\n kind: SpanKind;\n\n /**\n * True if end() has been called on the Span\n */\n endCalled: boolean;\n\n /**\n * The start time of the Span\n */\n readonly startTime: TimeInput;\n\n /**\n * The id of the parent Span, if any.\n */\n readonly parentSpanId?: string;\n\n /**\n * Known attributes, if any.\n */\n readonly attributes: Attributes;\n\n private _context: SpanContext;\n private readonly _tracer: Tracer;\n\n /**\n * Starts a new Span.\n * @param parentTracer The tracer that created this Span\n * @param name The name of the span.\n * @param context The SpanContext this span belongs to\n * @param kind The SpanKind of this Span\n * @param parentSpanId The identifier of the parent Span\n * @param startTime The startTime of the event (defaults to now)\n */\n constructor(\n parentTracer: Tracer,\n name: string,\n context: SpanContext,\n kind: SpanKind,\n parentSpanId?: string,\n startTime: TimeInput = Date.now()\n ) {\n super();\n this._tracer = parentTracer;\n this.name = name;\n this.kind = kind;\n this.startTime = startTime;\n this.parentSpanId = parentSpanId;\n this.status = {\n code: CanonicalCode.OK\n };\n this.endCalled = false;\n this._context = context;\n this.attributes = {};\n }\n\n /**\n * Returns the Tracer that created this Span\n */\n tracer(): Tracer {\n return this._tracer;\n }\n\n /**\n * Returns the SpanContext associated with this Span.\n */\n context(): SpanContext {\n return this._context;\n }\n\n /**\n * Marks the end of Span execution.\n * @param _endTime The time to use as the Span's end time. Defaults to\n * the current time.\n */\n end(_endTime?: number): void {\n this.endCalled = true;\n }\n\n /**\n * Sets a status on the span. Overrides the default of CanonicalCode.OK.\n * @param status The status to set.\n */\n setStatus(status: Status): this {\n this.status = status;\n return this;\n }\n\n /**\n * Returns whether this span will be recorded\n */\n isRecording(): boolean {\n return true;\n }\n\n /**\n * Sets an attribute on the Span\n * @param key the attribute key\n * @param value the attribute value\n */\n setAttribute(key: string, value: unknown): this {\n this.attributes[key] = value;\n return this;\n }\n\n /**\n * Sets attributes on the Span\n * @param attributes the attributes to add\n */\n setAttributes(attributes: Attributes): this {\n for (const key of Object.keys(attributes)) {\n this.attributes[key] = attributes[key];\n }\n return this;\n }\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { TestSpan } from \"./testSpan\";\nimport { NoOpTracer } from \"../noop/noOpTracer\";\nimport { SpanContext, SpanKind, SpanOptions, TraceFlags } from \"@opentelemetry/api\";\n\n/**\n * Simple representation of a Span that only has name and child relationships.\n * Children should be arranged in the order they were created.\n */\nexport interface SpanGraphNode {\n /**\n * The Span name\n */\n name: string;\n /**\n * All child Spans of this Span\n */\n children: SpanGraphNode[];\n}\n\n/**\n * Contains all the spans for a particular TraceID\n * starting at unparented roots\n */\nexport interface SpanGraph {\n /**\n * All Spans without a parentSpanId\n */\n roots: SpanGraphNode[];\n}\n\n/**\n * A mock tracer useful for testing\n */\nexport class TestTracer extends NoOpTracer {\n private traceIdCounter = 0;\n private getNextTraceId(): string {\n this.traceIdCounter++;\n return String(this.traceIdCounter);\n }\n\n private spanIdCounter = 0;\n private getNextSpanId(): string {\n this.spanIdCounter++;\n return String(this.spanIdCounter);\n }\n\n private rootSpans: TestSpan[] = [];\n private knownSpans: TestSpan[] = [];\n\n /**\n * Returns all Spans that were created without a parent\n */\n getRootSpans(): TestSpan[] {\n return this.rootSpans;\n }\n\n /**\n * Returns all Spans this Tracer knows about\n */\n getKnownSpans(): TestSpan[] {\n return this.knownSpans;\n }\n\n /**\n * Returns all Spans where end() has not been called\n */\n getActiveSpans(): TestSpan[] {\n return this.knownSpans.filter((span) => {\n return !span.endCalled;\n });\n }\n\n /**\n * Return all Spans for a particular trace, grouped by their\n * parent Span in a tree-like structure\n * @param traceId The traceId to return the graph for\n */\n getSpanGraph(traceId: string): SpanGraph {\n const traceSpans = this.knownSpans.filter((span) => {\n return span.context().traceId === traceId;\n });\n\n const roots: SpanGraphNode[] = [];\n const nodeMap: Map<string, SpanGraphNode> = new Map<string, SpanGraphNode>();\n\n for (const span of traceSpans) {\n const spanId = span.context().spanId;\n const node: SpanGraphNode = {\n name: span.name,\n children: []\n };\n nodeMap.set(spanId, node);\n if (span.parentSpanId) {\n const parent = nodeMap.get(span.parentSpanId);\n if (!parent) {\n throw new Error(\n `Span with name ${node.name} has an unknown parentSpan with id ${span.parentSpanId}`\n );\n }\n parent.children.push(node);\n } else {\n roots.push(node);\n }\n }\n\n return {\n roots\n };\n }\n\n /**\n * Starts a new Span.\n * @param name The name of the span.\n * @param options The SpanOptions used during Span creation.\n */\n startSpan(name: string, options: SpanOptions = {}): TestSpan {\n const parentContext = this._getParentContext(options);\n\n let traceId: string;\n let isRootSpan = false;\n\n if (parentContext && parentContext.traceId) {\n traceId = parentContext.traceId;\n } else {\n traceId = this.getNextTraceId();\n isRootSpan = true;\n }\n\n const context: SpanContext = {\n traceId,\n spanId: this.getNextSpanId(),\n traceFlags: TraceFlags.NONE\n };\n const span = new TestSpan(\n this,\n name,\n context,\n options.kind || SpanKind.INTERNAL,\n parentContext ? parentContext.spanId : undefined,\n options.startTime\n );\n this.knownSpans.push(span);\n if (isRootSpan) {\n this.rootSpans.push(span);\n }\n return span;\n }\n\n private _getParentContext(options: SpanOptions): SpanContext | undefined {\n const parent = options.parent;\n let result: SpanContext | undefined;\n if (parent) {\n if (\"traceId\" in parent) {\n result = parent;\n } else {\n result = parent.context();\n }\n }\n return result;\n }\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { SpanContext, TraceFlags } from \"../interfaces\";\n\nconst VERSION = \"00\";\n\n/**\n * Generates a `SpanContext` given a `traceparent` header value.\n * @param traceParent Serialized span context data as a `traceparent` header value.\n * @returns The `SpanContext` generated from the `traceparent` value.\n */\nexport function extractSpanContextFromTraceParentHeader(\n traceParentHeader: string\n): SpanContext | undefined {\n const parts = traceParentHeader.split(\"-\");\n\n if (parts.length !== 4) {\n return;\n }\n\n const [version, traceId, spanId, traceOptions] = parts;\n\n if (version !== VERSION) {\n return;\n }\n\n const traceFlags = parseInt(traceOptions, 16);\n\n const spanContext: SpanContext = {\n spanId,\n traceId,\n traceFlags\n };\n\n return spanContext;\n}\n\n/**\n * Generates a `traceparent` value given a span context.\n * @param spanContext Contains context for a specific span.\n * @returns The `spanContext` represented as a `traceparent` value.\n */\nexport function getTraceParentHeader(spanContext: SpanContext): string | undefined {\n const missingFields: string[] = [];\n if (!spanContext.traceId) {\n missingFields.push(\"traceId\");\n }\n if (!spanContext.spanId) {\n missingFields.push(\"spanId\");\n }\n\n if (missingFields.length) {\n return;\n }\n\n const flags = spanContext.traceFlags || TraceFlags.NONE;\n const hexFlags = flags.toString(16);\n const traceFlags = hexFlags.length === 1 ? `0${hexFlags}` : hexFlags;\n\n // https://www.w3.org/TR/trace-context/#traceparent-header-field-values\n return `${VERSION}-${spanContext.traceId}-${spanContext.spanId}-${traceFlags}`;\n}\n"],"names":["TraceFlags","__extends","CanonicalCode","SpanKind"],"mappings":";;;;;;;AAAA;AAKA;;;;IAGA;KAqEC;;;;IAjEC,0BAAO,GAAP;QACE,OAAO;YACL,MAAM,EAAE,EAAE;YACV,OAAO,EAAE,EAAE;YACX,UAAU,EAAEA,cAAU,CAAC,IAAI;SAC5B,CAAC;KACH;;;;;;IAOD,sBAAG,GAAH,UAAI,QAAiB;;KAEpB;;;;;;IAOD,+BAAY,GAAZ,UAAa,IAAY,EAAE,MAAe;QACxC,OAAO,IAAI,CAAC;KACb;;;;;IAMD,gCAAa,GAAb,UAAc,WAAuB;QACnC,OAAO,IAAI,CAAC;KACb;;;;;;IAOD,2BAAQ,GAAR,UAAS,KAAa,EAAE,WAAwB;QAC9C,OAAO,IAAI,CAAC;KACb;;;;;IAMD,4BAAS,GAAT,UAAU,OAAe;QACvB,OAAO,IAAI,CAAC;KACb;;;;;IAMD,6BAAU,GAAV,UAAW,KAAa;QACtB,OAAO,IAAI,CAAC;KACb;;;;IAKD,8BAAW,GAAX;QACE,OAAO,KAAK,CAAC;KACd;IACH,eAAC;AAAD,CAAC;;AC7ED;AACA,AAKA;;;;AAIA;IAAA;KAkCC;;;;;;IA5BC,8BAAS,GAAT,UAAU,KAAa,EAAE,QAAsB;QAC7C,OAAO,IAAI,QAAQ,EAAE,CAAC;KACvB;;;;IAKD,mCAAc,GAAd;QACE,OAAO,IAAI,Q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,OAAO,GAA0B,KAAK,GAA/B,EAAE,MAAM,GAAkB,KAAK,GAAvB,EAAE,YAAY,GAAI,KAAK,GAAT,CAAU;IAEvD,IAAI,OAAO,KAAK,OAAO,EAAE;QACvB,OAAO;KACR;IAED,IAAM,UAAU,GAAG,QAAQ,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;IAE9C,IAAM,WAAW,GAAgB;QAC/B,MAAM,QAAA;QACN,OAAO,SAAA;QACP,UAAU,YAAA;KACX,CAAC;IAEF,OAAO,WAAW,CAAC;AACrB,CAAC;AAED;;;;;AAKA,SAAgB,oBAAoB,CAAC,WAAwB;IAC3D,IAAM,aAAa,GAAa,EAAE,CAAC;IACnC,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE;QACxB,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;KAC/B;IACD,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE;QACvB,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;KAC9B;IAED,IAAI,aAAa,CAAC,MAAM,EAAE;QACxB,OAAO;KACR;IAED,IAAM,KAAK,GAAG,WAAW,CAAC,UAAU,iBAAoB;IACxD,IAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACpC,IAAM,UAAU,GAAG,QAAQ,CAAC,MAAM,KAAK,CAAC,GAAG,MAAI,QAAU,GAAG,QAAQ,CAAC;;IAGrE,OAAU,OAAO,SAAI,WAAW,CAAC,OAAO,SAAI,WAAW,CAAC,MAAM,SAAI,UAAY,CAAC;AACjF,CAAC;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../src/tracingContext.ts","../src/instrumenter.ts","../src/tracingClient.ts"],"sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { TracingClient, TracingContext, TracingSpan } from \"./interfaces\";\n\n/** @internal */\nexport const knownContextKeys = {\n span: Symbol.for(\"@azure/core-tracing span\"),\n namespace: Symbol.for(\"@azure/core-tracing namespace\"),\n client: Symbol.for(\"@azure/core-tracing client\"),\n parentContext: Symbol.for(\"@azure/core-tracing parent context\"),\n};\n\n/**\n * Creates a new {@link TracingContext} with the given options.\n * @param options - A set of known keys that may be set on the context.\n * @returns A new {@link TracingContext} with the given options.\n *\n * @internal\n */\nexport function createTracingContext(options: CreateTracingContextOptions = {}): TracingContext {\n let context: TracingContext = new TracingContextImpl(options.parentContext);\n if (options.span) {\n context = context.setValue(knownContextKeys.span, options.span);\n }\n if (options.client) {\n context = context.setValue(knownContextKeys.client, options.client);\n }\n if (options.namespace) {\n context = context.setValue(knownContextKeys.namespace, options.namespace);\n }\n return context;\n}\n\n/** @internal */\nexport class TracingContextImpl implements TracingContext {\n private _contextMap: Map<symbol, unknown>;\n constructor(initialContext?: TracingContext) {\n this._contextMap =\n initialContext instanceof TracingContextImpl\n ? new Map<symbol, unknown>(initialContext._contextMap)\n : new Map();\n }\n\n setValue(key: symbol, value: unknown): TracingContext {\n const newContext = new TracingContextImpl(this);\n newContext._contextMap.set(key, value);\n return newContext;\n }\n\n getValue(key: symbol): unknown {\n return this._contextMap.get(key);\n }\n\n deleteValue(key: symbol): TracingContext {\n const newContext = new TracingContextImpl(this);\n newContext._contextMap.delete(key);\n return newContext;\n }\n}\n\n/**\n * Represents a set of items that can be set when creating a new {@link TracingContext}.\n */\nexport interface CreateTracingContextOptions {\n /** The {@link parentContext} - the newly created context will contain all the values of the parent context unless overriden. */\n parentContext?: TracingContext;\n /** An initial span to set on the context. */\n span?: TracingSpan;\n /** The tracing client used to create this context. */\n client?: TracingClient;\n /** The namespace to set on any child spans. */\n namespace?: string;\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { Instrumenter, InstrumenterSpanOptions, TracingContext, TracingSpan } from \"./interfaces\";\nimport { createTracingContext } from \"./tracingContext\";\n\nexport function createDefaultTracingSpan(): TracingSpan {\n return {\n end: () => {\n // noop\n },\n isRecording: () => false,\n recordException: () => {\n // noop\n },\n setAttribute: () => {\n // noop\n },\n setStatus: () => {\n // noop\n },\n };\n}\n\nexport function createDefaultInstrumenter(): Instrumenter {\n return {\n createRequestHeaders: (): Record<string, string> => {\n return {};\n },\n parseTraceparentHeader: (): TracingContext | undefined => {\n return undefined;\n },\n startSpan: (\n _name: string,\n spanOptions: InstrumenterSpanOptions\n ): { span: TracingSpan; tracingContext: TracingContext } => {\n return {\n span: createDefaultTracingSpan(),\n tracingContext: createTracingContext({ parentContext: spanOptions.tracingContext }),\n };\n },\n withContext<\n CallbackArgs extends unknown[],\n Callback extends (...args: CallbackArgs) => ReturnType<Callback>\n >(\n _context: TracingContext,\n callback: Callback,\n ...callbackArgs: CallbackArgs\n ): ReturnType<Callback> {\n return callback(...callbackArgs);\n },\n };\n}\n\n/** @internal */\nlet instrumenterImplementation: Instrumenter | undefined;\n\n/**\n * Extends the Azure SDK with support for a given instrumenter implementation.\n *\n * @param instrumenter - The instrumenter implementation to use.\n */\nexport function useInstrumenter(instrumenter: Instrumenter): void {\n instrumenterImplementation = instrumenter;\n}\n\n/**\n * Gets the currently set instrumenter, a No-Op instrumenter by default.\n *\n * @returns The currently set instrumenter\n */\nexport function getInstrumenter(): Instrumenter {\n if (!instrumenterImplementation) {\n instrumenterImplementation = createDefaultInstrumenter();\n }\n return instrumenterImplementation;\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n OperationTracingOptions,\n Resolved,\n TracingClient,\n TracingClientOptions,\n TracingContext,\n TracingSpan,\n TracingSpanOptions,\n} from \"./interfaces\";\nimport { getInstrumenter } from \"./instrumenter\";\nimport { knownContextKeys } from \"./tracingContext\";\n\n/**\n * Creates a new tracing client.\n *\n * @param options - Options used to configure the tracing client.\n * @returns - An instance of {@link TracingClient}.\n */\nexport function createTracingClient(options: TracingClientOptions): TracingClient {\n const { namespace, packageName, packageVersion } = options;\n\n function startSpan<Options extends { tracingOptions?: OperationTracingOptions }>(\n name: string,\n operationOptions?: Options,\n spanOptions?: TracingSpanOptions\n ): {\n span: TracingSpan;\n updatedOptions: Options;\n } {\n const startSpanResult = getInstrumenter().startSpan(name, {\n ...spanOptions,\n packageName: packageName,\n packageVersion: packageVersion,\n tracingContext: operationOptions?.tracingOptions?.tracingContext,\n });\n let tracingContext = startSpanResult.tracingContext;\n const span = startSpanResult.span;\n if (!tracingContext.getValue(knownContextKeys.namespace)) {\n tracingContext = tracingContext.setValue(knownContextKeys.namespace, namespace);\n }\n span.setAttribute(\"az.namespace\", tracingContext.getValue(knownContextKeys.namespace));\n const updatedOptions = {\n ...operationOptions,\n tracingOptions: {\n tracingContext: tracingContext,\n },\n } as Options;\n return {\n span,\n updatedOptions,\n };\n }\n\n async function withSpan<\n Options extends { tracingOptions?: { tracingContext?: TracingContext } },\n Callback extends (\n updatedOptions: Options,\n span: Omit<TracingSpan, \"end\">\n ) => ReturnType<Callback>\n >(\n name: string,\n operationOptions: Options,\n callback: Callback,\n spanOptions?: TracingSpanOptions\n ): Promise<Resolved<ReturnType<Callback>>> {\n const { span, updatedOptions } = startSpan(name, operationOptions, spanOptions);\n try {\n const result = await withContext(updatedOptions.tracingOptions!.tracingContext!, () =>\n Promise.resolve(callback(updatedOptions, span))\n );\n span.setStatus({ status: \"success\" });\n return result as ReturnType<typeof withSpan>;\n } catch (err) {\n span.setStatus({ status: \"error\", error: err });\n throw err;\n } finally {\n span.end();\n }\n }\n\n function withContext<\n CallbackArgs extends unknown[],\n Callback extends (...args: CallbackArgs) => ReturnType<Callback>\n >(\n context: TracingContext,\n callback: Callback,\n ...callbackArgs: CallbackArgs\n ): ReturnType<Callback> {\n return getInstrumenter().withContext(context, callback, ...callbackArgs);\n }\n\n /**\n * Parses a traceparent header value into a span identifier.\n *\n * @param traceparentHeader - The traceparent header to parse.\n * @returns An implementation-specific identifier for the span.\n */\n function parseTraceparentHeader(traceparentHeader: string): TracingContext | undefined {\n return getInstrumenter().parseTraceparentHeader(traceparentHeader);\n }\n\n /**\n * Creates a set of request headers to propagate tracing information to a backend.\n *\n * @param tracingContext - The context containing the span to serialize.\n * @returns The set of headers to add to a request.\n */\n function createRequestHeaders(tracingContext?: TracingContext): Record<string, string> {\n return getInstrumenter().createRequestHeaders(tracingContext);\n }\n\n return {\n startSpan,\n withSpan,\n withContext,\n parseTraceparentHeader,\n createRequestHeaders,\n };\n}\n"],"names":[],"mappings":";;;;AAAA;AACA;AAIA;AACO,MAAM,gBAAgB,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,0BAA0B,CAAC;IAC5C,SAAS,EAAE,MAAM,CAAC,GAAG,CAAC,+BAA+B,CAAC;IACtD,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC;IAChD,aAAa,EAAE,MAAM,CAAC,GAAG,CAAC,oCAAoC,CAAC;CAChE,CAAC;AAEF;;;;;;;SAOgB,oBAAoB,CAAC,UAAuC,EAAE;IAC5E,IAAI,OAAO,GAAmB,IAAI,kBAAkB,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IAC5E,IAAI,OAAO,CAAC,IAAI,EAAE;QAChB,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;KACjE;IACD,IAAI,OAAO,CAAC,MAAM,EAAE;QAClB,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;KACrE;IACD,IAAI,OAAO,CAAC,SAAS,EAAE;QACrB,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAC,SAAS,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;KAC3E;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;MACa,kBAAkB;IAE7B,YAAY,cAA+B;QACzC,IAAI,CAAC,WAAW;YACd,cAAc,YAAY,kBAAkB;kBACxC,IAAI,GAAG,CAAkB,cAAc,CAAC,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AC,IAAI,EAAE,gBAAgB,EAAE,WAAW,CAAC,CAAC;QAChF,IAAI;YACF,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,cAAc,CAAC,cAAe,CAAC,cAAe,EAAE,MAC/E,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC,CAChD,CAAC;YACF,IAAI,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;YACtC,OAAO,MAAqC,CAAC;SAC9C;QAAC,OAAO,GAAG,EAAE;YACZ,IAAI,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;YAChD,MAAM,GAAG,CAAC;SACX;gBAAS;YACR,IAAI,CAAC,GAAG,EAAE,CAAC;SACZ;KACF;IAED,SAAS,WAAW,CAIlB,OAAuB,EACvB,QAAkB,EAClB,GAAG,YAA0B;QAE7B,OAAO,eAAe,EAAE,CAAC,WAAW,CAAC,OAAO,EAAE,QAAQ,EAAE,GAAG,YAAY,CAAC,CAAC;KAC1E;;;;;;;IAQD,SAAS,sBAAsB,CAAC,iBAAyB;QACvD,OAAO,eAAe,EAAE,CAAC,sBAAsB,CAAC,iBAAiB,CAAC,CAAC;KACpE;;;;;;;IAQD,SAAS,oBAAoB,CAAC,cAA+B;QAC3D,OAAO,eAAe,EAAE,CAAC,oBAAoB,CAAC,cAAc,CAAC,CAAC;KAC/D;IAED,OAAO;QACL,SAAS;QACT,QAAQ;QACR,WAAW;QACX,sBAAsB;QACtB,oBAAoB;KACrB,CAAC;AACJ;;;;;"}
@@ -1,13 +1,5 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT license.
3
- export { getTracer, setTracer } from "./tracerProxy";
4
- // Tracers and wrappers
5
- export { NoOpSpan } from "./tracers/noop/noOpSpan";
6
- export { NoOpTracer } from "./tracers/noop/noOpTracer";
7
- export { OpenCensusSpanWrapper } from "./tracers/opencensus/openCensusSpanWrapper";
8
- export { OpenCensusTracerWrapper } from "./tracers/opencensus/openCensusTracerWrapper";
9
- export { TestTracer } from "./tracers/test/testTracer";
10
- export { TestSpan } from "./tracers/test/testSpan";
11
- // Utilities
12
- export { extractSpanContextFromTraceParentHeader, getTraceParentHeader } from "./utils/traceParentHeader";
3
+ export { useInstrumenter } from "./instrumenter";
4
+ export { createTracingClient } from "./tracingClient";
13
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAErD,uBAAuB;AACvB,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4CAA4C,CAAC;AACnF,OAAO,EAAE,uBAAuB,EAAE,MAAM,8CAA8C,CAAC;AACvF,OAAO,EAAE,UAAU,EAA4B,MAAM,2BAA2B,CAAC;AACjF,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAQnD,YAAY;AACZ,OAAO,EACL,uCAAuC,EACvC,oBAAoB,EACrB,MAAM,2BAA2B,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nexport { getTracer, setTracer } from \"./tracerProxy\";\n\n// Tracers and wrappers\nexport { NoOpSpan } from \"./tracers/noop/noOpSpan\";\nexport { NoOpTracer } from \"./tracers/noop/noOpTracer\";\nexport { OpenCensusSpanWrapper } from \"./tracers/opencensus/openCensusSpanWrapper\";\nexport { OpenCensusTracerWrapper } from \"./tracers/opencensus/openCensusTracerWrapper\";\nexport { TestTracer, SpanGraph, SpanGraphNode } from \"./tracers/test/testTracer\";\nexport { TestSpan } from \"./tracers/test/testSpan\";\n\n// Shared interfaces\nexport { SpanContext, SpanOptions, TraceFlags } from \"./interfaces\";\n\n// OT interfaces\nexport { SpanContext as OTSpanContext, SpanOptions as OTSpanOptions } from \"@opentelemetry/api\";\n\n// Utilities\nexport {\n extractSpanContextFromTraceParentHeader,\n getTraceParentHeader\n} from \"./utils/traceParentHeader\";\n\n// OpenCensus Interfaces\nexport { Tracer as OpenCensusTracer, Span as OpenCensusSpan } from \"@opencensus/web-types\";\n\nexport { OperationTracingOptions } from \"./interfaces\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAkBlC,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nexport {\n Instrumenter,\n InstrumenterSpanOptions,\n OperationTracingOptions,\n Resolved,\n SpanStatus,\n SpanStatusError,\n SpanStatusSuccess,\n TracingClient,\n TracingClientOptions,\n TracingContext,\n TracingSpan,\n TracingSpanKind,\n TracingSpanLink,\n TracingSpanOptions,\n} from \"./interfaces\";\nexport { useInstrumenter } from \"./instrumenter\";\nexport { createTracingClient } from \"./tracingClient\";\n"]}
@@ -0,0 +1,61 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT license.
3
+ import { createTracingContext } from "./tracingContext";
4
+ export function createDefaultTracingSpan() {
5
+ return {
6
+ end: () => {
7
+ // noop
8
+ },
9
+ isRecording: () => false,
10
+ recordException: () => {
11
+ // noop
12
+ },
13
+ setAttribute: () => {
14
+ // noop
15
+ },
16
+ setStatus: () => {
17
+ // noop
18
+ },
19
+ };
20
+ }
21
+ export function createDefaultInstrumenter() {
22
+ return {
23
+ createRequestHeaders: () => {
24
+ return {};
25
+ },
26
+ parseTraceparentHeader: () => {
27
+ return undefined;
28
+ },
29
+ startSpan: (_name, spanOptions) => {
30
+ return {
31
+ span: createDefaultTracingSpan(),
32
+ tracingContext: createTracingContext({ parentContext: spanOptions.tracingContext }),
33
+ };
34
+ },
35
+ withContext(_context, callback, ...callbackArgs) {
36
+ return callback(...callbackArgs);
37
+ },
38
+ };
39
+ }
40
+ /** @internal */
41
+ let instrumenterImplementation;
42
+ /**
43
+ * Extends the Azure SDK with support for a given instrumenter implementation.
44
+ *
45
+ * @param instrumenter - The instrumenter implementation to use.
46
+ */
47
+ export function useInstrumenter(instrumenter) {
48
+ instrumenterImplementation = instrumenter;
49
+ }
50
+ /**
51
+ * Gets the currently set instrumenter, a No-Op instrumenter by default.
52
+ *
53
+ * @returns The currently set instrumenter
54
+ */
55
+ export function getInstrumenter() {
56
+ if (!instrumenterImplementation) {
57
+ instrumenterImplementation = createDefaultInstrumenter();
58
+ }
59
+ return instrumenterImplementation;
60
+ }
61
+ //# sourceMappingURL=instrumenter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instrumenter.js","sourceRoot":"","sources":["../../src/instrumenter.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAExD,MAAM,UAAU,wBAAwB;IACtC,OAAO;QACL,GAAG,EAAE,GAAG,EAAE;YACR,OAAO;QACT,CAAC;QACD,WAAW,EAAE,GAAG,EAAE,CAAC,KAAK;QACxB,eAAe,EAAE,GAAG,EAAE;YACpB,OAAO;QACT,CAAC;QACD,YAAY,EAAE,GAAG,EAAE;YACjB,OAAO;QACT,CAAC;QACD,SAAS,EAAE,GAAG,EAAE;YACd,OAAO;QACT,CAAC;KACF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,yBAAyB;IACvC,OAAO;QACL,oBAAoB,EAAE,GAA2B,EAAE;YACjD,OAAO,EAAE,CAAC;QACZ,CAAC;QACD,sBAAsB,EAAE,GAA+B,EAAE;YACvD,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,SAAS,EAAE,CACT,KAAa,EACb,WAAoC,EACmB,EAAE;YACzD,OAAO;gBACL,IAAI,EAAE,wBAAwB,EAAE;gBAChC,cAAc,EAAE,oBAAoB,CAAC,EAAE,aAAa,EAAE,WAAW,CAAC,cAAc,EAAE,CAAC;aACpF,CAAC;QACJ,CAAC;QACD,WAAW,CAIT,QAAwB,EACxB,QAAkB,EAClB,GAAG,YAA0B;YAE7B,OAAO,QAAQ,CAAC,GAAG,YAAY,CAAC,CAAC;QACnC,CAAC;KACF,CAAC;AACJ,CAAC;AAED,gBAAgB;AAChB,IAAI,0BAAoD,CAAC;AAEzD;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,YAA0B;IACxD,0BAA0B,GAAG,YAAY,CAAC;AAC5C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe;IAC7B,IAAI,CAAC,0BAA0B,EAAE;QAC/B,0BAA0B,GAAG,yBAAyB,EAAE,CAAC;KAC1D;IACD,OAAO,0BAA0B,CAAC;AACpC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { Instrumenter, InstrumenterSpanOptions, TracingContext, TracingSpan } from \"./interfaces\";\nimport { createTracingContext } from \"./tracingContext\";\n\nexport function createDefaultTracingSpan(): TracingSpan {\n return {\n end: () => {\n // noop\n },\n isRecording: () => false,\n recordException: () => {\n // noop\n },\n setAttribute: () => {\n // noop\n },\n setStatus: () => {\n // noop\n },\n };\n}\n\nexport function createDefaultInstrumenter(): Instrumenter {\n return {\n createRequestHeaders: (): Record<string, string> => {\n return {};\n },\n parseTraceparentHeader: (): TracingContext | undefined => {\n return undefined;\n },\n startSpan: (\n _name: string,\n spanOptions: InstrumenterSpanOptions\n ): { span: TracingSpan; tracingContext: TracingContext } => {\n return {\n span: createDefaultTracingSpan(),\n tracingContext: createTracingContext({ parentContext: spanOptions.tracingContext }),\n };\n },\n withContext<\n CallbackArgs extends unknown[],\n Callback extends (...args: CallbackArgs) => ReturnType<Callback>\n >(\n _context: TracingContext,\n callback: Callback,\n ...callbackArgs: CallbackArgs\n ): ReturnType<Callback> {\n return callback(...callbackArgs);\n },\n };\n}\n\n/** @internal */\nlet instrumenterImplementation: Instrumenter | undefined;\n\n/**\n * Extends the Azure SDK with support for a given instrumenter implementation.\n *\n * @param instrumenter - The instrumenter implementation to use.\n */\nexport function useInstrumenter(instrumenter: Instrumenter): void {\n instrumenterImplementation = instrumenter;\n}\n\n/**\n * Gets the currently set instrumenter, a No-Op instrumenter by default.\n *\n * @returns The currently set instrumenter\n */\nexport function getInstrumenter(): Instrumenter {\n if (!instrumenterImplementation) {\n instrumenterImplementation = createDefaultInstrumenter();\n }\n return instrumenterImplementation;\n}\n"]}
@@ -1,3 +1,4 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT license.
3
+ export {};
3
4
  //# sourceMappingURL=interfaces.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../src/interfaces.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n/**\n * Shorthand enum for common traceFlags values inside SpanContext\n */\nexport const enum TraceFlags {\n /** No flag set. */\n NONE = 0x0,\n /** Caller is collecting trace information. */\n SAMPLED = 0x1\n}\n\n/**\n * A light interface that tries to be structurally compatible with OpenTelemetry\n */\nexport interface SpanContext {\n /**\n * UUID of a trace.\n */\n traceId: string;\n /**\n * UUID of a Span.\n */\n spanId: string;\n /**\n * https://www.w3.org/TR/trace-context/#trace-flags\n */\n traceFlags: number;\n}\n\n/**\n * An interface that enables manual propagation of Spans\n */\nexport interface SpanOptions {\n /**\n * The SpanContext that refers to a parent span, if any.\n * A null value indicates that this should be a new root span,\n * rather than potentially detecting a span via a context manager.\n */\n parent?: SpanContext | null;\n /**\n * Attributes to set on the Span\n */\n attributes?: { [key: string]: unknown };\n}\n\n/**\n * Tracing options to set on an operation.\n */\nexport interface OperationTracingOptions {\n /**\n * OpenTelemetry SpanOptions used to create a span when tracing is enabled.\n */\n spanOptions?: SpanOptions;\n}\n"]}
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../src/interfaces.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n/**\n * A narrower version of TypeScript 4.5's Awaited type which Recursively\n * unwraps the \"awaited type\", emulating the behavior of `await`.\n */\nexport type Resolved<T> = T extends { then(onfulfilled: infer F): any } // `await` only unwraps object types with a callable `then`. Non-object types are not unwrapped\n ? F extends (value: infer V) => any // if the argument to `then` is callable, extracts the first argument\n ? Resolved<V> // recursively unwrap the value\n : never // the argument to `then` was not callable\n : T; // non-object or non-thenable\n\n/**\n * Represents a client that can integrate with the currently configured {@link Instrumenter}.\n *\n * Create an instance using {@link createTracingClient}.\n */\nexport interface TracingClient {\n /**\n * Wraps a callback in a tracing span, calls the callback, and closes the span.\n *\n * This is the primary interface for using Tracing and will handle error recording as well as setting the status on the span.\n *\n * Both synchronous and asynchronous functions will be awaited in order to reflect the result of the callback on the span.\n *\n * Example:\n *\n * ```ts\n * const myOperationResult = await tracingClient.withSpan(\"myClassName.myOperationName\", options, (updatedOptions) => myOperation(updatedOptions));\n * ```\n * @param name - The name of the span. By convention this should be `${className}.${methodName}`.\n * @param operationOptions - The original options passed to the method. The callback will receive these options with the newly created {@link TracingContext}.\n * @param callback - The callback to be invoked with the updated options and newly created {@link TracingSpan}.\n */\n withSpan<\n Options extends { tracingOptions?: OperationTracingOptions },\n Callback extends (\n updatedOptions: Options,\n span: Omit<TracingSpan, \"end\">\n ) => ReturnType<Callback>\n >(\n name: string,\n operationOptions: Options,\n callback: Callback,\n spanOptions?: TracingSpanOptions\n ): Promise<Resolved<ReturnType<Callback>>>;\n /**\n * Starts a given span but does not set it as the active span.\n *\n * You must end the span using {@link TracingSpan.end}.\n *\n * Most of the time you will want to use {@link withSpan} instead.\n *\n * @param name - The name of the span. By convention this should be `${className}.${methodName}`.\n * @param operationOptions - The original operation options.\n * @param spanOptions - The options to use when creating the span.\n *\n * @returns A {@link TracingSpan} and the updated operation options.\n */\n startSpan<Options extends { tracingOptions?: OperationTracingOptions }>(\n name: string,\n operationOptions?: Options,\n spanOptions?: TracingSpanOptions\n ): { span: TracingSpan; updatedOptions: Options };\n /**\n * Wraps a callback with an active context and calls the callback.\n * Depending on the implementation, this may set the globally available active context.\n *\n * Useful when you want to leave the boundaries of the SDK (make a request or callback to user code) and are unable to use the {@link withSpan} API.\n *\n * @param context - The {@link TracingContext} to use as the active context in the scope of the callback.\n * @param callback - The callback to be invoked with the given context set as the globally active context.\n * @param callbackArgs - The callback arguments.\n */\n withContext<\n CallbackArgs extends unknown[],\n Callback extends (...args: CallbackArgs) => ReturnType<Callback>\n >(\n context: TracingContext,\n callback: Callback,\n ...callbackArgs: CallbackArgs\n ): ReturnType<Callback>;\n\n /**\n * Parses a traceparent header value into a {@link TracingSpanContext}.\n *\n * @param traceparentHeader - The traceparent header to parse.\n * @returns An implementation-specific identifier for the span.\n */\n parseTraceparentHeader(traceparentHeader: string): TracingContext | undefined;\n\n /**\n * Creates a set of request headers to propagate tracing information to a backend.\n *\n * @param tracingContext - The context containing the span to propagate.\n * @returns The set of headers to add to a request.\n */\n createRequestHeaders(tracingContext?: TracingContext): Record<string, string>;\n}\n\n/**\n * Options that can be passed to {@link createTracingClient}\n */\nexport interface TracingClientOptions {\n /** The value of the az.namespace tracing attribute on newly created spans. */\n namespace: string;\n /** The name of the package invoking this trace. */\n packageName: string;\n /** An optional version of the package invoking this trace. */\n packageVersion?: string;\n}\n\n/** The kind of span. */\nexport type TracingSpanKind = \"client\" | \"server\" | \"producer\" | \"consumer\" | \"internal\";\n\n/** Options used to configure the newly created span. */\nexport interface TracingSpanOptions {\n /** The kind of span. Implementations should default this to \"client\". */\n spanKind?: TracingSpanKind;\n /** A collection of {@link TracingSpanLink} to link to this span. */\n spanLinks?: TracingSpanLink[];\n /** Initial set of attributes to set on a span. */\n spanAttributes?: { [key: string]: unknown };\n}\n\n/** A pointer from the current {@link TracingSpan} to another span in the same or a different trace. */\nexport interface TracingSpanLink {\n /** The {@link TracingContext} containing the span context to link to. */\n tracingContext: TracingContext;\n /** A set of attributes on the link. */\n attributes?: { [key: string]: unknown };\n}\n\n/**\n * Represents an implementation agnostic instrumenter.\n */\nexport interface Instrumenter {\n /**\n * Creates a new {@link TracingSpan} with the given name and options and sets it on a new context.\n * @param name - The name of the span. By convention this should be `${className}.${methodName}`.\n * @param spanOptions - The options to use when creating the span.\n *\n * @returns A {@link TracingSpan} that can be used to end the span, and the context this span has been set on.\n */\n startSpan(\n name: string,\n spanOptions: InstrumenterSpanOptions\n ): { span: TracingSpan; tracingContext: TracingContext };\n /**\n * Wraps a callback with an active context and calls the callback.\n * Depending on the implementation, this may set the globally available active context.\n *\n * @param context - The {@link TracingContext} to use as the active context in the scope of the callback.\n * @param callback - The callback to be invoked with the given context set as the globally active context.\n * @param callbackArgs - The callback arguments.\n */\n withContext<\n CallbackArgs extends unknown[],\n Callback extends (...args: CallbackArgs) => ReturnType<Callback>\n >(\n context: TracingContext,\n callback: Callback,\n ...callbackArgs: CallbackArgs\n ): ReturnType<Callback>;\n\n /**\n * Provides an implementation-specific method to parse a {@link https://www.w3.org/TR/trace-context/#traceparent-header}\n * into a {@link TracingSpanContext} which can be used to link non-parented spans together.\n */\n parseTraceparentHeader(traceparentHeader: string): TracingContext | undefined;\n /**\n * Provides an implementation-specific method to serialize a {@link TracingSpan} to a set of headers.\n * @param tracingContext - The context containing the span to serialize.\n */\n createRequestHeaders(tracingContext?: TracingContext): Record<string, string>;\n}\n\n/**\n * Options passed to {@link Instrumenter.startSpan} as a superset of {@link TracingSpanOptions}.\n */\nexport interface InstrumenterSpanOptions extends TracingSpanOptions {\n /** The name of the package invoking this trace. */\n packageName: string;\n /** The version of the package invoking this trace. */\n packageVersion?: string;\n /** The current tracing context. Defaults to an implementation-specific \"active\" context. */\n tracingContext?: TracingContext;\n}\n\n/**\n * Status representing a successful operation that can be sent to {@link TracingSpan.setStatus}\n */\nexport type SpanStatusSuccess = { status: \"success\" };\n\n/**\n * Status representing an error that can be sent to {@link TracingSpan.setStatus}\n */\nexport type SpanStatusError = { status: \"error\"; error?: Error | string };\n\n/**\n * Represents the statuses that can be passed to {@link TracingSpan.setStatus}.\n *\n * By default, all spans will be created with status \"unset\".\n */\nexport type SpanStatus = SpanStatusSuccess | SpanStatusError;\n\n/**\n * Represents an implementation agnostic tracing span.\n */\nexport interface TracingSpan {\n /**\n * Sets the status of the span. When an error is provided, it will be recorded on the span as well.\n *\n * @param status - The {@link SpanStatus} to set on the span.\n */\n setStatus(status: SpanStatus): void;\n\n /**\n * Sets a given attribute on a span.\n *\n * @param name - The attribute's name.\n * @param value - The attribute's value to set. May be any non-nullish value.\n */\n setAttribute(name: string, value: unknown): void;\n\n /**\n * Ends the span.\n */\n end(): void;\n\n /**\n * Records an exception on a {@link TracingSpan} without modifying its status.\n *\n * When recording an unhandled exception that should fail the span, please use {@link TracingSpan.setStatus} instead.\n *\n * @param exception - The exception to record on the span.\n *\n */\n recordException(exception: Error | string): void;\n\n /**\n * Returns true if this {@link TracingSpan} is recording information.\n *\n * Depending on the span implementation, this may return false if the span is not being sampled.\n */\n isRecording(): boolean;\n}\n\n/** An immutable context bag of tracing values for the current operation. */\nexport interface TracingContext {\n /**\n * Sets a given object on a context.\n * @param key - The key of the given context value.\n * @param value - The value to set on the context.\n *\n * @returns - A new context with the given value set.\n */\n setValue(key: symbol, value: unknown): TracingContext;\n /**\n * Gets an object from the context if it exists.\n * @param key - The key of the given context value.\n *\n * @returns - The value of the given context value if it exists, otherwise `undefined`.\n */\n getValue(key: symbol): unknown;\n /**\n * Deletes an object from the context if it exists.\n * @param key - The key of the given context value to delete.\n */\n deleteValue(key: symbol): TracingContext;\n}\n\n/**\n * Tracing options to set on an operation.\n */\nexport interface OperationTracingOptions {\n /** The context to use for created Tracing Spans. */\n tracingContext?: TracingContext;\n}\n"]}
@@ -0,0 +1,74 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT license.
3
+ import { getInstrumenter } from "./instrumenter";
4
+ import { knownContextKeys } from "./tracingContext";
5
+ /**
6
+ * Creates a new tracing client.
7
+ *
8
+ * @param options - Options used to configure the tracing client.
9
+ * @returns - An instance of {@link TracingClient}.
10
+ */
11
+ export function createTracingClient(options) {
12
+ const { namespace, packageName, packageVersion } = options;
13
+ function startSpan(name, operationOptions, spanOptions) {
14
+ var _a;
15
+ const startSpanResult = getInstrumenter().startSpan(name, Object.assign(Object.assign({}, spanOptions), { packageName: packageName, packageVersion: packageVersion, tracingContext: (_a = operationOptions === null || operationOptions === void 0 ? void 0 : operationOptions.tracingOptions) === null || _a === void 0 ? void 0 : _a.tracingContext }));
16
+ let tracingContext = startSpanResult.tracingContext;
17
+ const span = startSpanResult.span;
18
+ if (!tracingContext.getValue(knownContextKeys.namespace)) {
19
+ tracingContext = tracingContext.setValue(knownContextKeys.namespace, namespace);
20
+ }
21
+ span.setAttribute("az.namespace", tracingContext.getValue(knownContextKeys.namespace));
22
+ const updatedOptions = Object.assign(Object.assign({}, operationOptions), { tracingOptions: {
23
+ tracingContext: tracingContext,
24
+ } });
25
+ return {
26
+ span,
27
+ updatedOptions,
28
+ };
29
+ }
30
+ async function withSpan(name, operationOptions, callback, spanOptions) {
31
+ const { span, updatedOptions } = startSpan(name, operationOptions, spanOptions);
32
+ try {
33
+ const result = await withContext(updatedOptions.tracingOptions.tracingContext, () => Promise.resolve(callback(updatedOptions, span)));
34
+ span.setStatus({ status: "success" });
35
+ return result;
36
+ }
37
+ catch (err) {
38
+ span.setStatus({ status: "error", error: err });
39
+ throw err;
40
+ }
41
+ finally {
42
+ span.end();
43
+ }
44
+ }
45
+ function withContext(context, callback, ...callbackArgs) {
46
+ return getInstrumenter().withContext(context, callback, ...callbackArgs);
47
+ }
48
+ /**
49
+ * Parses a traceparent header value into a span identifier.
50
+ *
51
+ * @param traceparentHeader - The traceparent header to parse.
52
+ * @returns An implementation-specific identifier for the span.
53
+ */
54
+ function parseTraceparentHeader(traceparentHeader) {
55
+ return getInstrumenter().parseTraceparentHeader(traceparentHeader);
56
+ }
57
+ /**
58
+ * Creates a set of request headers to propagate tracing information to a backend.
59
+ *
60
+ * @param tracingContext - The context containing the span to serialize.
61
+ * @returns The set of headers to add to a request.
62
+ */
63
+ function createRequestHeaders(tracingContext) {
64
+ return getInstrumenter().createRequestHeaders(tracingContext);
65
+ }
66
+ return {
67
+ startSpan,
68
+ withSpan,
69
+ withContext,
70
+ parseTraceparentHeader,
71
+ createRequestHeaders,
72
+ };
73
+ }
74
+ //# sourceMappingURL=tracingClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tracingClient.js","sourceRoot":"","sources":["../../src/tracingClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAWlC,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAA6B;IAC/D,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC;IAE3D,SAAS,SAAS,CAChB,IAAY,EACZ,gBAA0B,EAC1B,WAAgC;;QAKhC,MAAM,eAAe,GAAG,eAAe,EAAE,CAAC,SAAS,CAAC,IAAI,kCACnD,WAAW,KACd,WAAW,EAAE,WAAW,EACxB,cAAc,EAAE,cAAc,EAC9B,cAAc,EAAE,MAAA,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,cAAc,0CAAE,cAAc,IAChE,CAAC;QACH,IAAI,cAAc,GAAG,eAAe,CAAC,cAAc,CAAC;QACpD,MAAM,IAAI,GAAG,eAAe,CAAC,IAAI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,EAAE,QAAQ,EAAE,GAAG,YAAY,CAAC,CAAC;IAC3E,CAAC;IAED;;;;;OAKG;IACH,SAAS,sBAAsB,CAAC,iBAAyB;QACvD,OAAO,eAAe,EAAE,CAAC,sBAAsB,CAAC,iBAAiB,CAAC,CAAC;IACrE,CAAC;IAED;;;;;OAKG;IACH,SAAS,oBAAoB,CAAC,cAA+B;QAC3D,OAAO,eAAe,EAAE,CAAC,oBAAoB,CAAC,cAAc,CAAC,CAAC;IAChE,CAAC;IAED,OAAO;QACL,SAAS;QACT,QAAQ;QACR,WAAW;QACX,sBAAsB;QACtB,oBAAoB;KACrB,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n OperationTracingOptions,\n Resolved,\n TracingClient,\n TracingClientOptions,\n TracingContext,\n TracingSpan,\n TracingSpanOptions,\n} from \"./interfaces\";\nimport { getInstrumenter } from \"./instrumenter\";\nimport { knownContextKeys } from \"./tracingContext\";\n\n/**\n * Creates a new tracing client.\n *\n * @param options - Options used to configure the tracing client.\n * @returns - An instance of {@link TracingClient}.\n */\nexport function createTracingClient(options: TracingClientOptions): TracingClient {\n const { namespace, packageName, packageVersion } = options;\n\n function startSpan<Options extends { tracingOptions?: OperationTracingOptions }>(\n name: string,\n operationOptions?: Options,\n spanOptions?: TracingSpanOptions\n ): {\n span: TracingSpan;\n updatedOptions: Options;\n } {\n const startSpanResult = getInstrumenter().startSpan(name, {\n ...spanOptions,\n packageName: packageName,\n packageVersion: packageVersion,\n tracingContext: operationOptions?.tracingOptions?.tracingContext,\n });\n let tracingContext = startSpanResult.tracingContext;\n const span = startSpanResult.span;\n if (!tracingContext.getValue(knownContextKeys.namespace)) {\n tracingContext = tracingContext.setValue(knownContextKeys.namespace, namespace);\n }\n span.setAttribute(\"az.namespace\", tracingContext.getValue(knownContextKeys.namespace));\n const updatedOptions = {\n ...operationOptions,\n tracingOptions: {\n tracingContext: tracingContext,\n },\n } as Options;\n return {\n span,\n updatedOptions,\n };\n }\n\n async function withSpan<\n Options extends { tracingOptions?: { tracingContext?: TracingContext } },\n Callback extends (\n updatedOptions: Options,\n span: Omit<TracingSpan, \"end\">\n ) => ReturnType<Callback>\n >(\n name: string,\n operationOptions: Options,\n callback: Callback,\n spanOptions?: TracingSpanOptions\n ): Promise<Resolved<ReturnType<Callback>>> {\n const { span, updatedOptions } = startSpan(name, operationOptions, spanOptions);\n try {\n const result = await withContext(updatedOptions.tracingOptions!.tracingContext!, () =>\n Promise.resolve(callback(updatedOptions, span))\n );\n span.setStatus({ status: \"success\" });\n return result as ReturnType<typeof withSpan>;\n } catch (err) {\n span.setStatus({ status: \"error\", error: err });\n throw err;\n } finally {\n span.end();\n }\n }\n\n function withContext<\n CallbackArgs extends unknown[],\n Callback extends (...args: CallbackArgs) => ReturnType<Callback>\n >(\n context: TracingContext,\n callback: Callback,\n ...callbackArgs: CallbackArgs\n ): ReturnType<Callback> {\n return getInstrumenter().withContext(context, callback, ...callbackArgs);\n }\n\n /**\n * Parses a traceparent header value into a span identifier.\n *\n * @param traceparentHeader - The traceparent header to parse.\n * @returns An implementation-specific identifier for the span.\n */\n function parseTraceparentHeader(traceparentHeader: string): TracingContext | undefined {\n return getInstrumenter().parseTraceparentHeader(traceparentHeader);\n }\n\n /**\n * Creates a set of request headers to propagate tracing information to a backend.\n *\n * @param tracingContext - The context containing the span to serialize.\n * @returns The set of headers to add to a request.\n */\n function createRequestHeaders(tracingContext?: TracingContext): Record<string, string> {\n return getInstrumenter().createRequestHeaders(tracingContext);\n }\n\n return {\n startSpan,\n withSpan,\n withContext,\n parseTraceparentHeader,\n createRequestHeaders,\n };\n}\n"]}
@@ -0,0 +1,52 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT license.
3
+ /** @internal */
4
+ export const knownContextKeys = {
5
+ span: Symbol.for("@azure/core-tracing span"),
6
+ namespace: Symbol.for("@azure/core-tracing namespace"),
7
+ client: Symbol.for("@azure/core-tracing client"),
8
+ parentContext: Symbol.for("@azure/core-tracing parent context"),
9
+ };
10
+ /**
11
+ * Creates a new {@link TracingContext} with the given options.
12
+ * @param options - A set of known keys that may be set on the context.
13
+ * @returns A new {@link TracingContext} with the given options.
14
+ *
15
+ * @internal
16
+ */
17
+ export function createTracingContext(options = {}) {
18
+ let context = new TracingContextImpl(options.parentContext);
19
+ if (options.span) {
20
+ context = context.setValue(knownContextKeys.span, options.span);
21
+ }
22
+ if (options.client) {
23
+ context = context.setValue(knownContextKeys.client, options.client);
24
+ }
25
+ if (options.namespace) {
26
+ context = context.setValue(knownContextKeys.namespace, options.namespace);
27
+ }
28
+ return context;
29
+ }
30
+ /** @internal */
31
+ export class TracingContextImpl {
32
+ constructor(initialContext) {
33
+ this._contextMap =
34
+ initialContext instanceof TracingContextImpl
35
+ ? new Map(initialContext._contextMap)
36
+ : new Map();
37
+ }
38
+ setValue(key, value) {
39
+ const newContext = new TracingContextImpl(this);
40
+ newContext._contextMap.set(key, value);
41
+ return newContext;
42
+ }
43
+ getValue(key) {
44
+ return this._contextMap.get(key);
45
+ }
46
+ deleteValue(key) {
47
+ const newContext = new TracingContextImpl(this);
48
+ newContext._contextMap.delete(key);
49
+ return newContext;
50
+ }
51
+ }
52
+ //# sourceMappingURL=tracingContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tracingContext.js","sourceRoot":"","sources":["../../src/tracingContext.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,gBAAgB;AAChB,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,0BAA0B,CAAC;IAC5C,SAAS,EAAE,MAAM,CAAC,GAAG,CAAC,+BAA+B,CAAC;IACtD,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC;IAChD,aAAa,EAAE,MAAM,CAAC,GAAG,CAAC,oCAAoC,CAAC;CAChE,CAAC;AAEF;;;;;;GAMG;AACH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MAAM,CAAC,GAAG,CAAC,CAAC;QACnC,OAAO,UAAU,CAAC;IACpB,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { TracingClient, TracingContext, TracingSpan } from \"./interfaces\";\n\n/** @internal */\nexport const knownContextKeys = {\n span: Symbol.for(\"@azure/core-tracing span\"),\n namespace: Symbol.for(\"@azure/core-tracing namespace\"),\n client: Symbol.for(\"@azure/core-tracing client\"),\n parentContext: Symbol.for(\"@azure/core-tracing parent context\"),\n};\n\n/**\n * Creates a new {@link TracingContext} with the given options.\n * @param options - A set of known keys that may be set on the context.\n * @returns A new {@link TracingContext} with the given options.\n *\n * @internal\n */\nexport function createTracingContext(options: CreateTracingContextOptions = {}): TracingContext {\n let context: TracingContext = new TracingContextImpl(options.parentContext);\n if (options.span) {\n context = context.setValue(knownContextKeys.span, options.span);\n }\n if (options.client) {\n context = context.setValue(knownContextKeys.client, options.client);\n }\n if (options.namespace) {\n context = context.setValue(knownContextKeys.namespace, options.namespace);\n }\n return context;\n}\n\n/** @internal */\nexport class TracingContextImpl implements TracingContext {\n private _contextMap: Map<symbol, unknown>;\n constructor(initialContext?: TracingContext) {\n this._contextMap =\n initialContext instanceof TracingContextImpl\n ? new Map<symbol, unknown>(initialContext._contextMap)\n : new Map();\n }\n\n setValue(key: symbol, value: unknown): TracingContext {\n const newContext = new TracingContextImpl(this);\n newContext._contextMap.set(key, value);\n return newContext;\n }\n\n getValue(key: symbol): unknown {\n return this._contextMap.get(key);\n }\n\n deleteValue(key: symbol): TracingContext {\n const newContext = new TracingContextImpl(this);\n newContext._contextMap.delete(key);\n return newContext;\n }\n}\n\n/**\n * Represents a set of items that can be set when creating a new {@link TracingContext}.\n */\nexport interface CreateTracingContextOptions {\n /** The {@link parentContext} - the newly created context will contain all the values of the parent context unless overriden. */\n parentContext?: TracingContext;\n /** An initial span to set on the context. */\n span?: TracingSpan;\n /** The tracing client used to create this context. */\n client?: TracingClient;\n /** The namespace to set on any child spans. */\n namespace?: string;\n}\n"]}
package/package.json CHANGED
@@ -1,38 +1,36 @@
1
1
  {
2
2
  "name": "@azure/core-tracing",
3
- "version": "1.0.0-preview.9",
3
+ "version": "1.0.0",
4
4
  "description": "Provides low-level interfaces and helper methods for tracing in Azure SDK",
5
5
  "sdk-type": "client",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist-esm/src/index.js",
8
- "browser": {
9
- "./dist-esm/src/utils/global.js": "./dist-esm/src/utils/global.browser.js"
8
+ "browser": {},
9
+ "react-native": {
10
+ "./dist/index.js": "./dist-esm/src/index.js"
10
11
  },
11
12
  "types": "types/core-tracing.d.ts",
12
13
  "scripts": {
13
14
  "audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit",
14
- "build:browser": "tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1",
15
- "build:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1",
16
- "build:samples": "cd samples && tsc -p .",
17
- "build:test": "tsc -p . && rollup -c rollup.test.config.js 2>&1",
18
- "build": "tsc -p . && rollup -c 2>&1 && api-extractor run --local",
15
+ "build:samples": "echo Obsolete",
16
+ "build:test": "tsc -p . && dev-tool run bundle",
17
+ "build": "npm run clean && tsc -p . && dev-tool run bundle && api-extractor run --local",
19
18
  "check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
20
- "clean": "rimraf dist dist-esm test-dist types *.tgz *.log",
19
+ "clean": "rimraf dist dist-* temp types *.tgz *.log",
21
20
  "execute:samples": "echo skipped",
22
21
  "extract-api": "tsc -p . && api-extractor run --local",
23
- "format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
22
+ "format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"",
24
23
  "integration-test:browser": "echo skipped",
25
24
  "integration-test:node": "echo skipped",
26
25
  "integration-test": "npm run integration-test:node && npm run integration-test:browser",
27
26
  "lint:fix": "eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]",
28
- "lint": "eslint package.json api-extractor.json src test --ext .ts -f html -o core-tracing-lintReport.html",
27
+ "lint": "eslint package.json api-extractor.json src test --ext .ts",
29
28
  "pack": "npm pack 2>&1",
30
- "prebuild": "npm run clean",
31
- "test:browser": "npm run build:test && npm run unit-test:browser && npm run integration-test:browser",
32
- "test:node": "npm run build:test && npm run unit-test:node && npm run integration-test:node",
33
- "test": "npm run build:test && npm run unit-test && npm run integration-test",
34
- "unit-test:browser": "echo skipped",
35
- "unit-test:node": "mocha test-dist/**/*.js --reporter ../../../common/tools/mocha-multi-reporter.js",
29
+ "test:browser": "npm run clean && npm run build:test && npm run unit-test:browser && npm run integration-test:browser",
30
+ "test:node": "npm run clean && tsc -p . && npm run unit-test:node && npm run integration-test:node",
31
+ "test": "npm run clean && tsc -p . && npm run unit-test:node && dev-tool run bundle && npm run unit-test:browser && npm run integration-test",
32
+ "unit-test:browser": "karma start --single-run",
33
+ "unit-test:node": "mocha -r esm -r ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 1200000 --full-trace --exclude \"test/**/browser/*.spec.ts\" \"test/**/*.spec.ts\"",
36
34
  "unit-test": "npm run unit-test:node && npm run unit-test:browser"
37
35
  },
38
36
  "files": [
@@ -46,7 +44,6 @@
46
44
  "keywords": [
47
45
  "azure",
48
46
  "tracing",
49
- "Azure",
50
47
  "cloud"
51
48
  ],
52
49
  "author": "Microsoft Corporation",
@@ -55,44 +52,50 @@
55
52
  "url": "https://github.com/Azure/azure-sdk-for-js/issues"
56
53
  },
57
54
  "engines": {
58
- "node": ">=8.0.0"
55
+ "node": ">=12.0.0"
59
56
  },
60
- "homepage": "https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/core/core-tracing/README.md",
57
+ "homepage": "https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/core/core-tracing/README.md",
61
58
  "sideEffects": false,
62
59
  "dependencies": {
63
- "@opencensus/web-types": "0.0.7",
64
- "@opentelemetry/api": "^0.10.2",
65
- "tslib": "^2.0.0"
60
+ "tslib": "^2.2.0"
66
61
  },
67
62
  "devDependencies": {
63
+ "@azure/core-auth": "^1.3.0",
64
+ "@azure/dev-tool": "^1.0.0",
68
65
  "@azure/eslint-plugin-azure-sdk": "^3.0.0",
69
- "@microsoft/api-extractor": "7.7.11",
70
- "@rollup/plugin-commonjs": "11.0.2",
71
- "@rollup/plugin-json": "^4.0.0",
72
- "@rollup/plugin-multi-entry": "^3.0.0",
73
- "@rollup/plugin-node-resolve": "^8.0.0",
74
- "@rollup/plugin-replace": "^2.2.0",
66
+ "@microsoft/api-extractor": "^7.18.11",
67
+ "@types/chai": "^4.1.6",
75
68
  "@types/mocha": "^7.0.2",
76
- "@types/node": "^8.0.0",
77
- "@typescript-eslint/eslint-plugin": "^2.0.0",
78
- "@typescript-eslint/parser": "^2.0.0",
79
- "assert": "^1.4.1",
69
+ "@types/node": "^12.0.0",
70
+ "chai": "^4.2.0",
80
71
  "cross-env": "^7.0.2",
81
- "eslint": "^6.1.0",
82
- "eslint-config-prettier": "^6.0.0",
83
- "eslint-plugin-no-null": "^1.0.2",
84
- "eslint-plugin-no-only-tests": "^2.3.0",
85
- "eslint-plugin-promise": "^4.1.1",
72
+ "eslint": "^7.15.0",
86
73
  "inherits": "^2.0.3",
74
+ "karma": "^6.2.0",
75
+ "karma-chrome-launcher": "^3.0.0",
76
+ "karma-coverage": "^2.0.0",
77
+ "karma-edge-launcher": "^0.4.2",
78
+ "karma-env-preprocessor": "^0.1.1",
79
+ "karma-firefox-launcher": "^1.1.0",
80
+ "karma-ie-launcher": "^1.0.0",
81
+ "karma-junit-reporter": "^2.0.1",
82
+ "karma-mocha": "^2.0.1",
83
+ "karma-mocha-reporter": "^2.2.5",
84
+ "karma-sourcemap-loader": "^0.3.8",
87
85
  "mocha": "^7.1.1",
88
- "mocha-junit-reporter": "^1.18.0",
89
- "prettier": "^1.16.4",
86
+ "mocha-junit-reporter": "^2.0.0",
87
+ "prettier": "^2.5.1",
90
88
  "rimraf": "^3.0.0",
91
- "rollup": "^1.16.3",
92
- "rollup-plugin-sourcemaps": "^0.4.2",
93
- "rollup-plugin-terser": "^5.1.1",
94
- "rollup-plugin-visualizer": "^4.0.4",
95
- "typescript": "~3.9.3",
96
- "util": "^0.12.1"
89
+ "typescript": "~4.2.0",
90
+ "util": "^0.12.1",
91
+ "sinon": "^9.0.2",
92
+ "@types/sinon": "^9.0.4"
93
+ },
94
+ "//sampleConfiguration": {
95
+ "disableDocsMs": true,
96
+ "productName": "Azure SDK Core",
97
+ "productSlugs": [
98
+ "azure"
99
+ ]
97
100
  }
98
101
  }