Commit iniziale

This commit is contained in:
Paolo A
2025-02-18 22:59:07 +00:00
commit 4bbf35cefb
6879 changed files with 623784 additions and 0 deletions

21
node_modules/@azure/core-tracing/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2020 Microsoft
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

37
node_modules/@azure/core-tracing/README.md generated vendored Normal file
View File

@@ -0,0 +1,37 @@
# Azure Core tracing library for JavaScript
This is the core tracing library that provides low-level interfaces and helper methods for tracing in Azure SDK JavaScript libraries which work in the browser and Node.js.
## Getting started
### Installation
This package is primarily used in Azure client libraries and not meant to be used directly by consumers of Azure SDKs.
## Key Concepts
- `TracingClient` is the primary interface providing tracing functionality to client libraries. Client libraries should only be aware of and interact with a `TracingClient` instance.
- A `TracingClient` implementation can be created using the `createTracingClient` factory function.
- `Instrumenter` provides an abstraction over an instrumentation and acts as the interop point for using third party libraries like OpenTelemetry. By default, a no-op `Instrumenter` is used. Customers who wish to enable `OpenTelemetry` based tracing will do so by installing and registering the [@azure/opentelemetry-instrumentation-azure-sdk] package.
- `TracingContext` is an **immutable** data container, used to pass operation-specific information around (such as span parenting information).
- `TracingSpan` is an abstraction of a `Span` which can be used to record events, attributes, and exceptions.
## Examples
Examples can be found in the `samples` folder.
## Next steps
You can build and run the tests locally by executing `rushx test`. Explore the `test` folder to see advanced usage and behavior of the public classes.
## Troubleshooting
If you run into issues while using this library, please feel free to [file an issue](https://github.com/Azure/azure-sdk-for-js/issues/new).
## Contributing
If you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test the code.
[@azure/opentelemetry-instrumentation-azure-sdk]: https://www.npmjs.com/package/@azure/opentelemetry-instrumentation-azure-sdk
![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fcore%2Fcore-tracing%2FREADME.png)

View File

@@ -0,0 +1,4 @@
export { AddEventOptions, Instrumenter, InstrumenterSpanOptions, OperationTracingOptions, OptionsWithTracingContext, Resolved, SpanStatus, SpanStatusError, SpanStatusSuccess, TracingClient, TracingClientOptions, TracingContext, TracingSpan, TracingSpanKind, TracingSpanLink, TracingSpanOptions, } from "./interfaces.js";
export { useInstrumenter } from "./instrumenter.js";
export { createTracingClient } from "./tracingClient.js";
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,eAAe,EACf,YAAY,EACZ,uBAAuB,EACvB,uBAAuB,EACvB,yBAAyB,EACzB,QAAQ,EACR,UAAU,EACV,eAAe,EACf,iBAAiB,EACjB,aAAa,EACb,oBAAoB,EACpB,cAAc,EACd,WAAW,EACX,eAAe,EACf,eAAe,EACf,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC"}

View File

@@ -0,0 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
export { useInstrumenter } from "./instrumenter.js";
export { createTracingClient } from "./tracingClient.js";
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAoBlC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nexport {\n AddEventOptions,\n Instrumenter,\n InstrumenterSpanOptions,\n OperationTracingOptions,\n OptionsWithTracingContext,\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.js\";\nexport { useInstrumenter } from \"./instrumenter.js\";\nexport { createTracingClient } from \"./tracingClient.js\";\n"]}

View File

@@ -0,0 +1,16 @@
import { Instrumenter, TracingSpan } from "./interfaces.js";
export declare function createDefaultTracingSpan(): TracingSpan;
export declare function createDefaultInstrumenter(): Instrumenter;
/**
* Extends the Azure SDK with support for a given instrumenter implementation.
*
* @param instrumenter - The instrumenter implementation to use.
*/
export declare function useInstrumenter(instrumenter: Instrumenter): void;
/**
* Gets the currently set instrumenter, a No-Op instrumenter by default.
*
* @returns The currently set instrumenter
*/
export declare function getInstrumenter(): Instrumenter;
//# sourceMappingURL=instrumenter.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"instrumenter.d.ts","sourceRoot":"","sources":["../../src/instrumenter.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,YAAY,EAGZ,WAAW,EACZ,MAAM,iBAAiB,CAAC;AAKzB,wBAAgB,wBAAwB,IAAI,WAAW,CAmBtD;AAED,wBAAgB,yBAAyB,IAAI,YAAY,CA4BxD;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,YAAY,EAAE,YAAY,GAAG,IAAI,CAEhE;AAED;;;;GAIG;AACH,wBAAgB,eAAe,IAAI,YAAY,CAK9C"}

View File

@@ -0,0 +1,63 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { createTracingContext } from "./tracingContext.js";
import { state } from "./state.js";
export function createDefaultTracingSpan() {
return {
end: () => {
// noop
},
isRecording: () => false,
recordException: () => {
// noop
},
setAttribute: () => {
// noop
},
setStatus: () => {
// noop
},
addEvent: () => {
// noop
},
};
}
export function createDefaultInstrumenter() {
return {
createRequestHeaders: () => {
return {};
},
parseTraceparentHeader: () => {
return undefined;
},
startSpan: (_name, spanOptions) => {
return {
span: createDefaultTracingSpan(),
tracingContext: createTracingContext({ parentContext: spanOptions.tracingContext }),
};
},
withContext(_context, callback, ...callbackArgs) {
return callback(...callbackArgs);
},
};
}
/**
* Extends the Azure SDK with support for a given instrumenter implementation.
*
* @param instrumenter - The instrumenter implementation to use.
*/
export function useInstrumenter(instrumenter) {
state.instrumenterImplementation = instrumenter;
}
/**
* Gets the currently set instrumenter, a No-Op instrumenter by default.
*
* @returns The currently set instrumenter
*/
export function getInstrumenter() {
if (!state.instrumenterImplementation) {
state.instrumenterImplementation = createDefaultInstrumenter();
}
return state.instrumenterImplementation;
}
//# sourceMappingURL=instrumenter.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"instrumenter.js","sourceRoot":"","sources":["../../src/instrumenter.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AASlC,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,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;QACD,QAAQ,EAAE,GAAG,EAAE;YACb,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;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,YAA0B;IACxD,KAAK,CAAC,0BAA0B,GAAG,YAAY,CAAC;AAClD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe;IAC7B,IAAI,CAAC,KAAK,CAAC,0BAA0B,EAAE,CAAC;QACtC,KAAK,CAAC,0BAA0B,GAAG,yBAAyB,EAAE,CAAC;IACjE,CAAC;IACD,OAAO,KAAK,CAAC,0BAA0B,CAAC;AAC1C,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport {\n Instrumenter,\n InstrumenterSpanOptions,\n TracingContext,\n TracingSpan,\n} from \"./interfaces.js\";\n\nimport { createTracingContext } from \"./tracingContext.js\";\nimport { state } from \"./state.js\";\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 addEvent: () => {\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/**\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 state.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 (!state.instrumenterImplementation) {\n state.instrumenterImplementation = createDefaultInstrumenter();\n }\n return state.instrumenterImplementation;\n}\n"]}

View File

@@ -0,0 +1,286 @@
/**
* A narrower version of TypeScript 4.5's Awaited type which Recursively
* unwraps the "awaited type", emulating the behavior of `await`.
*/
export type Resolved<T> = T extends {
then(onfulfilled: infer F): any;
} ? F extends (value: infer V) => any ? Resolved<V> : never : T;
/**
* Represents a client that can integrate with the currently configured {@link Instrumenter}.
*
* Create an instance using {@link createTracingClient}.
*/
export interface TracingClient {
/**
* Wraps a callback in a tracing span, calls the callback, and closes the span.
*
* This is the primary interface for using Tracing and will handle error recording as well as setting the status on the span.
*
* Both synchronous and asynchronous functions will be awaited in order to reflect the result of the callback on the span.
*
* Example:
*
* ```ts snippet:with_span_example
* import { createTracingClient } from "@azure/core-tracing";
*
* const tracingClient = createTracingClient({
* namespace: "test.namespace",
* packageName: "test-package",
* packageVersion: "1.0.0",
* });
* const options = {};
* const myOperationResult = await tracingClient.withSpan(
* "myClassName.myOperationName",
* options,
* (updatedOptions) => {
* // Do something with the updated options.
* return "myOperationResult";
* },
* );
* ```
* @param name - The name of the span. By convention this should be `${className}.${methodName}`.
* @param operationOptions - The original options passed to the method. The callback will receive these options with the newly created {@link TracingContext}.
* @param callback - The callback to be invoked with the updated options and newly created {@link TracingSpan}.
*/
withSpan<Options extends {
tracingOptions?: OperationTracingOptions;
}, Callback extends (updatedOptions: Options, span: Omit<TracingSpan, "end">) => ReturnType<Callback>>(name: string, operationOptions: Options, callback: Callback, spanOptions?: TracingSpanOptions): Promise<Resolved<ReturnType<Callback>>>;
/**
* Starts a given span but does not set it as the active span.
*
* You must end the span using {@link TracingSpan.end}.
*
* Most of the time you will want to use {@link withSpan} instead.
*
* @param name - The name of the span. By convention this should be `${className}.${methodName}`.
* @param operationOptions - The original operation options.
* @param spanOptions - The options to use when creating the span.
*
* @returns A {@link TracingSpan} and the updated operation options.
*/
startSpan<Options extends {
tracingOptions?: OperationTracingOptions;
}>(name: string, operationOptions?: Options, spanOptions?: TracingSpanOptions): {
span: TracingSpan;
updatedOptions: OptionsWithTracingContext<Options>;
};
/**
* Wraps a callback with an active context and calls the callback.
* Depending on the implementation, this may set the globally available active context.
*
* 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.
*
* @param context - The {@link TracingContext} to use as the active context in the scope of the callback.
* @param callback - The callback to be invoked with the given context set as the globally active context.
* @param callbackArgs - The callback arguments.
*/
withContext<CallbackArgs extends unknown[], Callback extends (...args: CallbackArgs) => ReturnType<Callback>>(context: TracingContext, callback: Callback, ...callbackArgs: CallbackArgs): ReturnType<Callback>;
/**
* Parses a traceparent header value into a {@link TracingSpanContext}.
*
* @param traceparentHeader - The traceparent header to parse.
* @returns An implementation-specific identifier for the span.
*/
parseTraceparentHeader(traceparentHeader: string): TracingContext | undefined;
/**
* Creates a set of request headers to propagate tracing information to a backend.
*
* @param tracingContext - The context containing the span to propagate.
* @returns The set of headers to add to a request.
*/
createRequestHeaders(tracingContext?: TracingContext): Record<string, string>;
}
/**
* Options that can be passed to {@link createTracingClient}
*/
export interface TracingClientOptions {
/** The value of the az.namespace tracing attribute on newly created spans. */
namespace: string;
/** The name of the package invoking this trace. */
packageName: string;
/** An optional version of the package invoking this trace. */
packageVersion?: string;
}
/** The kind of span. */
export type TracingSpanKind = "client" | "server" | "producer" | "consumer" | "internal";
/** Options used to configure the newly created span. */
export interface TracingSpanOptions {
/** The kind of span. Implementations should default this to "client". */
spanKind?: TracingSpanKind;
/** A collection of {@link TracingSpanLink} to link to this span. */
spanLinks?: TracingSpanLink[];
/** Initial set of attributes to set on a span. */
spanAttributes?: {
[key: string]: unknown;
};
}
/** A pointer from the current {@link TracingSpan} to another span in the same or a different trace. */
export interface TracingSpanLink {
/** The {@link TracingContext} containing the span context to link to. */
tracingContext: TracingContext;
/** A set of attributes on the link. */
attributes?: {
[key: string]: unknown;
};
}
/**
* Represents an implementation agnostic instrumenter.
*/
export interface Instrumenter {
/**
* Creates a new {@link TracingSpan} with the given name and options and sets it on a new context.
* @param name - The name of the span. By convention this should be `${className}.${methodName}`.
* @param spanOptions - The options to use when creating the span.
*
* @returns A {@link TracingSpan} that can be used to end the span, and the context this span has been set on.
*/
startSpan(name: string, spanOptions: InstrumenterSpanOptions): {
span: TracingSpan;
tracingContext: TracingContext;
};
/**
* Wraps a callback with an active context and calls the callback.
* Depending on the implementation, this may set the globally available active context.
*
* @param context - The {@link TracingContext} to use as the active context in the scope of the callback.
* @param callback - The callback to be invoked with the given context set as the globally active context.
* @param callbackArgs - The callback arguments.
*/
withContext<CallbackArgs extends unknown[], Callback extends (...args: CallbackArgs) => ReturnType<Callback>>(context: TracingContext, callback: Callback, ...callbackArgs: CallbackArgs): ReturnType<Callback>;
/**
* Provides an implementation-specific method to parse a {@link https://www.w3.org/TR/trace-context/#traceparent-header}
* into a {@link TracingSpanContext} which can be used to link non-parented spans together.
*/
parseTraceparentHeader(traceparentHeader: string): TracingContext | undefined;
/**
* Provides an implementation-specific method to serialize a {@link TracingSpan} to a set of headers.
* @param tracingContext - The context containing the span to serialize.
*/
createRequestHeaders(tracingContext?: TracingContext): Record<string, string>;
}
/**
* Options passed to {@link Instrumenter.startSpan} as a superset of {@link TracingSpanOptions}.
*/
export interface InstrumenterSpanOptions extends TracingSpanOptions {
/** The name of the package invoking this trace. */
packageName: string;
/** The version of the package invoking this trace. */
packageVersion?: string;
/** The current tracing context. Defaults to an implementation-specific "active" context. */
tracingContext?: TracingContext;
}
/**
* Status representing a successful operation that can be sent to {@link TracingSpan.setStatus}
*/
export type SpanStatusSuccess = {
status: "success";
};
/**
* Status representing an error that can be sent to {@link TracingSpan.setStatus}
*/
export type SpanStatusError = {
status: "error";
error?: Error | string;
};
/**
* Represents the statuses that can be passed to {@link TracingSpan.setStatus}.
*
* By default, all spans will be created with status "unset".
*/
export type SpanStatus = SpanStatusSuccess | SpanStatusError;
/**
* Represents options you can pass to {@link TracingSpan.addEvent}.
*/
export interface AddEventOptions {
/**
* A set of attributes to attach to the event.
*/
attributes?: Record<string, unknown>;
/**
* The start time of the event.
*/
startTime?: Date;
}
/**
* Represents an implementation agnostic tracing span.
*/
export interface TracingSpan {
/**
* Sets the status of the span. When an error is provided, it will be recorded on the span as well.
*
* @param status - The {@link SpanStatus} to set on the span.
*/
setStatus(status: SpanStatus): void;
/**
* Sets a given attribute on a span.
*
* @param name - The attribute's name.
* @param value - The attribute's value to set. May be any non-nullish value.
*/
setAttribute(name: string, value: unknown): void;
/**
* Ends the span.
*/
end(): void;
/**
* Records an exception on a {@link TracingSpan} without modifying its status.
*
* When recording an unhandled exception that should fail the span, please use {@link TracingSpan.setStatus} instead.
*
* @param exception - The exception to record on the span.
*
*/
recordException(exception: Error | string): void;
/**
* Returns true if this {@link TracingSpan} is recording information.
*
* Depending on the span implementation, this may return false if the span is not being sampled.
*/
isRecording(): boolean;
/**
* Adds an event to the span.
*/
addEvent?(name: string, options?: AddEventOptions): void;
}
/** An immutable context bag of tracing values for the current operation. */
export interface TracingContext {
/**
* Sets a given object on a context.
* @param key - The key of the given context value.
* @param value - The value to set on the context.
*
* @returns - A new context with the given value set.
*/
setValue(key: symbol, value: unknown): TracingContext;
/**
* Gets an object from the context if it exists.
* @param key - The key of the given context value.
*
* @returns - The value of the given context value if it exists, otherwise `undefined`.
*/
getValue(key: symbol): unknown;
/**
* Deletes an object from the context if it exists.
* @param key - The key of the given context value to delete.
*/
deleteValue(key: symbol): TracingContext;
}
/**
* Tracing options to set on an operation.
*/
export interface OperationTracingOptions {
/** The context to use for created Tracing Spans. */
tracingContext?: TracingContext;
}
/**
* A utility type for when we know a TracingContext has been set
* as part of an operation's options.
*/
export type OptionsWithTracingContext<Options extends {
tracingOptions?: OperationTracingOptions;
}> = Options & {
tracingOptions: {
tracingContext: TracingContext;
};
};
//# sourceMappingURL=interfaces.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../src/interfaces.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,CAAC,SAAS;IAAE,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC,GAAG,GAAG,CAAA;CAAE,GACnE,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,GAAG,GAC/B,QAAQ,CAAC,CAAC,CAAC,GACX,KAAK,GACP,CAAC,CAAC;AAEN;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACH,QAAQ,CACN,OAAO,SAAS;QAAE,cAAc,CAAC,EAAE,u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QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,cAAc,CAAC;IACtD;;;;;OAKG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;IAC/B;;;OAGG;IACH,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,CAAC;CAC1C;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,oDAAoD;IACpD,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC;AAED;;;GAGG;AACH,MAAM,MAAM,yBAAyB,CACnC,OAAO,SAAS;IAAE,cAAc,CAAC,EAAE,uBAAuB,CAAA;CAAE,IAC1D,OAAO,GAAG;IACZ,cAAc,EAAE;QACd,cAAc,EAAE,cAAc,CAAC;KAChC,CAAC;CACH,CAAC"}

View File

@@ -0,0 +1,4 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
export {};
//# sourceMappingURL=interfaces.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,3 @@
{
"type": "module"
}

View File

@@ -0,0 +1 @@
{"version":3,"file":"state-browser.d.mts","sourceRoot":"","sources":["../../src/state-browser.mts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C;;GAEG;AACH,eAAO,MAAM,KAAK;gCACyB,YAAY,GAAG,SAAS;CAClE,CAAC"}

View File

@@ -0,0 +1 @@
{"version":3,"file":"state-browser.mjs","sourceRoot":"","sources":["../../src/state-browser.mts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC;;GAEG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,0BAA0B,EAAE,SAAqC;CAClE,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { Instrumenter } from \"./interfaces.js\";\n\n/**\n * Browser-only implementation of the module's state. The browser esm variant will not load the commonjs state, so we do not need to share state between the two.\n */\nexport const state = {\n instrumenterImplementation: undefined as Instrumenter | undefined,\n};\n"]}

View File

@@ -0,0 +1,8 @@
import { Instrumenter } from "./interfaces.js";
/**
* Browser-only implementation of the module's state. The browser esm variant will not load the commonjs state, so we do not need to share state between the two.
*/
export declare const state: {
instrumenterImplementation: Instrumenter | undefined;
};
//# sourceMappingURL=state-browser.d.mts.map

View File

@@ -0,0 +1,9 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
/**
* Browser-only implementation of the module's state. The browser esm variant will not load the commonjs state, so we do not need to share state between the two.
*/
export const state = {
instrumenterImplementation: undefined,
};
//# sourceMappingURL=state-browser.mjs.map

View File

@@ -0,0 +1,9 @@
import { TracingClient, TracingClientOptions } from "./interfaces.js";
/**
* Creates a new tracing client.
*
* @param options - Options used to configure the tracing client.
* @returns - An instance of {@link TracingClient}.
*/
export declare function createTracingClient(options: TracingClientOptions): TracingClient;
//# sourceMappingURL=tracingClient.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"tracingClient.d.ts","sourceRoot":"","sources":["../../src/tracingClient.ts"],"names":[],"mappings":"AAGA,OAAO,EAIL,aAAa,EACb,oBAAoB,EAIrB,MAAM,iBAAiB,CAAC;AAIzB;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,GAAG,aAAa,CAkGhF"}

View File

@@ -0,0 +1,74 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { getInstrumenter } from "./instrumenter.js";
import { knownContextKeys } from "./tracingContext.js";
/**
* Creates a new tracing client.
*
* @param options - Options used to configure the tracing client.
* @returns - An instance of {@link TracingClient}.
*/
export function createTracingClient(options) {
const { namespace, packageName, packageVersion } = options;
function startSpan(name, operationOptions, spanOptions) {
var _a;
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 }));
let tracingContext = startSpanResult.tracingContext;
const span = startSpanResult.span;
if (!tracingContext.getValue(knownContextKeys.namespace)) {
tracingContext = tracingContext.setValue(knownContextKeys.namespace, namespace);
}
span.setAttribute("az.namespace", tracingContext.getValue(knownContextKeys.namespace));
const updatedOptions = Object.assign({}, operationOptions, {
tracingOptions: Object.assign(Object.assign({}, operationOptions === null || operationOptions === void 0 ? void 0 : operationOptions.tracingOptions), { tracingContext }),
});
return {
span,
updatedOptions,
};
}
async function withSpan(name, operationOptions, callback, spanOptions) {
const { span, updatedOptions } = startSpan(name, operationOptions, spanOptions);
try {
const result = await withContext(updatedOptions.tracingOptions.tracingContext, () => Promise.resolve(callback(updatedOptions, span)));
span.setStatus({ status: "success" });
return result;
}
catch (err) {
span.setStatus({ status: "error", error: err });
throw err;
}
finally {
span.end();
}
}
function withContext(context, callback, ...callbackArgs) {
return getInstrumenter().withContext(context, callback, ...callbackArgs);
}
/**
* Parses a traceparent header value into a span identifier.
*
* @param traceparentHeader - The traceparent header to parse.
* @returns An implementation-specific identifier for the span.
*/
function parseTraceparentHeader(traceparentHeader) {
return getInstrumenter().parseTraceparentHeader(traceparentHeader);
}
/**
* Creates a set of request headers to propagate tracing information to a backend.
*
* @param tracingContext - The context containing the span to serialize.
* @returns The set of headers to add to a request.
*/
function createRequestHeaders(tracingContext) {
return getInstrumenter().createRequestHeaders(tracingContext);
}
return {
startSpan,
withSpan,
withContext,
parseTraceparentHeader,
createRequestHeaders,
};
}
//# sourceMappingURL=tracingClient.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,34 @@
import { TracingContext, TracingSpan } from "./interfaces.js";
/** @internal */
export declare const knownContextKeys: {
span: symbol;
namespace: symbol;
};
/**
* Creates a new {@link TracingContext} with the given options.
* @param options - A set of known keys that may be set on the context.
* @returns A new {@link TracingContext} with the given options.
*
* @internal
*/
export declare function createTracingContext(options?: CreateTracingContextOptions): TracingContext;
/** @internal */
export declare class TracingContextImpl implements TracingContext {
private _contextMap;
constructor(initialContext?: TracingContext);
setValue(key: symbol, value: unknown): TracingContext;
getValue(key: symbol): unknown;
deleteValue(key: symbol): TracingContext;
}
/**
* Represents a set of items that can be set when creating a new {@link TracingContext}.
*/
export interface CreateTracingContextOptions {
/** The {@link parentContext} - the newly created context will contain all the values of the parent context unless overridden. */
parentContext?: TracingContext;
/** An initial span to set on the context. */
span?: TracingSpan;
/** The namespace to set on any child spans. */
namespace?: string;
}
//# sourceMappingURL=tracingContext.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"tracingContext.d.ts","sourceRoot":"","sources":["../../src/tracingContext.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9D,gBAAgB;AAChB,eAAO,MAAM,gBAAgB;;;CAG5B,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,GAAE,2BAAgC,GAAG,cAAc,CAS9F;AAED,gBAAgB;AAChB,qBAAa,kBAAmB,YAAW,cAAc;IACvD,OAAO,CAAC,WAAW,CAAuB;gBAC9B,cAAc,CAAC,EAAE,cAAc;IAO3C,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,cAAc;IAMrD,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAI9B,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc;CAKzC;AAED;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C,iIAAiI;IACjI,aAAa,CAAC,EAAE,cAAc,CAAC;IAC/B,6CAA6C;IAC7C,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,+CAA+C;IAC/C,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB"}

View File

@@ -0,0 +1,47 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
/** @internal */
export const knownContextKeys = {
span: Symbol.for("@azure/core-tracing span"),
namespace: Symbol.for("@azure/core-tracing namespace"),
};
/**
* Creates a new {@link TracingContext} with the given options.
* @param options - A set of known keys that may be set on the context.
* @returns A new {@link TracingContext} with the given options.
*
* @internal
*/
export function createTracingContext(options = {}) {
let context = new TracingContextImpl(options.parentContext);
if (options.span) {
context = context.setValue(knownContextKeys.span, options.span);
}
if (options.namespace) {
context = context.setValue(knownContextKeys.namespace, options.namespace);
}
return context;
}
/** @internal */
export class TracingContextImpl {
constructor(initialContext) {
this._contextMap =
initialContext instanceof TracingContextImpl
? new Map(initialContext._contextMap)
: new Map();
}
setValue(key, value) {
const newContext = new TracingContextImpl(this);
newContext._contextMap.set(key, value);
return newContext;
}
getValue(key) {
return this._contextMap.get(key);
}
deleteValue(key) {
const newContext = new TracingContextImpl(this);
newContext._contextMap.delete(key);
return newContext;
}
}
//# sourceMappingURL=tracingContext.js.map

View File

@@ -0,0 +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;CACvD,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAAC,UAAuC,EAAE;IAC5E,IAAI,OAAO,GAAmB,IAAI,kBAAkB,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IAC5E,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;QACjB,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAClE,CAAC;IACD,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;QACtB,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAC,SAAS,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IAC5E,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,gBAAgB;AAChB,MAAM,OAAO,kBAAkB;IAE7B,YAAY,cAA+B;QACzC,IAAI,CAAC,WAAW;YACd,cAAc,YAAY,kBAAkB;gBAC1C,CAAC,CAAC,IAAI,GAAG,CAAkB,cAAc,CAAC,WAAW,CAAC;gBACtD,CAAC,CAAC,IAAI,GAAG,EAAE,CAAC;IAClB,CAAC;IAED,QAAQ,CAAC,GAAW,EAAE,KAAc;QAClC,MAAM,UAAU,GAAG,IAAI,kBAAkB,CAAC,IAAI,CAAC,CAAC;QAChD,UAAU,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACvC,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,QAAQ,CAAC,GAAW;QAClB,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACnC,CAAC;IAED,WAAW,CAAC,GAAW;QACrB,MAAM,UAAU,GAAG,IAAI,kBAAkB,CAAC,IAAI,CAAC,CAAC;QAChD,UAAU,CAAC,WAAW,CAAC,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 { TracingContext, TracingSpan } from \"./interfaces.js\";\n\n/** @internal */\nexport const knownContextKeys = {\n span: Symbol.for(\"@azure/core-tracing span\"),\n namespace: Symbol.for(\"@azure/core-tracing namespace\"),\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.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 overridden. */\n parentContext?: TracingContext;\n /** An initial span to set on the context. */\n span?: TracingSpan;\n /** The namespace to set on any child spans. */\n namespace?: string;\n}\n"]}

View File

@@ -0,0 +1,4 @@
export { AddEventOptions, Instrumenter, InstrumenterSpanOptions, OperationTracingOptions, OptionsWithTracingContext, Resolved, SpanStatus, SpanStatusError, SpanStatusSuccess, TracingClient, TracingClientOptions, TracingContext, TracingSpan, TracingSpanKind, TracingSpanLink, TracingSpanOptions, } from "./interfaces.js";
export { useInstrumenter } from "./instrumenter.js";
export { createTracingClient } from "./tracingClient.js";
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,eAAe,EACf,YAAY,EACZ,uBAAuB,EACvB,uBAAuB,EACvB,yBAAyB,EACzB,QAAQ,EACR,UAAU,EACV,eAAe,EACf,iBAAiB,EACjB,aAAa,EACb,oBAAoB,EACpB,cAAc,EACd,WAAW,EACX,eAAe,EACf,eAAe,EACf,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC"}

View File

@@ -0,0 +1,10 @@
"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.createTracingClient = exports.useInstrumenter = void 0;
var instrumenter_js_1 = require("./instrumenter.js");
Object.defineProperty(exports, "useInstrumenter", { enumerable: true, get: function () { return instrumenter_js_1.useInstrumenter; } });
var tracingClient_js_1 = require("./tracingClient.js");
Object.defineProperty(exports, "createTracingClient", { enumerable: true, get: function () { return tracingClient_js_1.createTracingClient; } });
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAoBlC,qDAAoD;AAA3C,kHAAA,eAAe,OAAA;AACxB,uDAAyD;AAAhD,uHAAA,mBAAmB,OAAA","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nexport {\n AddEventOptions,\n Instrumenter,\n InstrumenterSpanOptions,\n OperationTracingOptions,\n OptionsWithTracingContext,\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.js\";\nexport { useInstrumenter } from \"./instrumenter.js\";\nexport { createTracingClient } from \"./tracingClient.js\";\n"]}

View File

@@ -0,0 +1,16 @@
import { Instrumenter, TracingSpan } from "./interfaces.js";
export declare function createDefaultTracingSpan(): TracingSpan;
export declare function createDefaultInstrumenter(): Instrumenter;
/**
* Extends the Azure SDK with support for a given instrumenter implementation.
*
* @param instrumenter - The instrumenter implementation to use.
*/
export declare function useInstrumenter(instrumenter: Instrumenter): void;
/**
* Gets the currently set instrumenter, a No-Op instrumenter by default.
*
* @returns The currently set instrumenter
*/
export declare function getInstrumenter(): Instrumenter;
//# sourceMappingURL=instrumenter.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"instrumenter.d.ts","sourceRoot":"","sources":["../../src/instrumenter.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,YAAY,EAGZ,WAAW,EACZ,MAAM,iBAAiB,CAAC;AAKzB,wBAAgB,wBAAwB,IAAI,WAAW,CAmBtD;AAED,wBAAgB,yBAAyB,IAAI,YAAY,CA4BxD;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,YAAY,EAAE,YAAY,GAAG,IAAI,CAEhE;AAED;;;;GAIG;AACH,wBAAgB,eAAe,IAAI,YAAY,CAK9C"}

View File

@@ -0,0 +1,69 @@
"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.createDefaultTracingSpan = createDefaultTracingSpan;
exports.createDefaultInstrumenter = createDefaultInstrumenter;
exports.useInstrumenter = useInstrumenter;
exports.getInstrumenter = getInstrumenter;
const tracingContext_js_1 = require("./tracingContext.js");
const state_js_1 = require("./state.js");
function createDefaultTracingSpan() {
return {
end: () => {
// noop
},
isRecording: () => false,
recordException: () => {
// noop
},
setAttribute: () => {
// noop
},
setStatus: () => {
// noop
},
addEvent: () => {
// noop
},
};
}
function createDefaultInstrumenter() {
return {
createRequestHeaders: () => {
return {};
},
parseTraceparentHeader: () => {
return undefined;
},
startSpan: (_name, spanOptions) => {
return {
span: createDefaultTracingSpan(),
tracingContext: (0, tracingContext_js_1.createTracingContext)({ parentContext: spanOptions.tracingContext }),
};
},
withContext(_context, callback, ...callbackArgs) {
return callback(...callbackArgs);
},
};
}
/**
* Extends the Azure SDK with support for a given instrumenter implementation.
*
* @param instrumenter - The instrumenter implementation to use.
*/
function useInstrumenter(instrumenter) {
state_js_1.state.instrumenterImplementation = instrumenter;
}
/**
* Gets the currently set instrumenter, a No-Op instrumenter by default.
*
* @returns The currently set instrumenter
*/
function getInstrumenter() {
if (!state_js_1.state.instrumenterImplementation) {
state_js_1.state.instrumenterImplementation = createDefaultInstrumenter();
}
return state_js_1.state.instrumenterImplementation;
}
//# sourceMappingURL=instrumenter.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"instrumenter.js","sourceRoot":"","sources":["../../src/instrumenter.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAYlC,4DAmBC;AAED,8DA4BC;AAOD,0CAEC;AAOD,0CAKC;AAzED,2DAA2D;AAC3D,yCAAmC;AAEnC,SAAgB,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;QACD,QAAQ,EAAE,GAAG,EAAE;YACb,OAAO;QACT,CAAC;KACF,CAAC;AACJ,CAAC;AAED,SAAgB,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,IAAA,wCAAoB,EAAC,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;;;;GAIG;AACH,SAAgB,eAAe,CAAC,YAA0B;IACxD,gBAAK,CAAC,0BAA0B,GAAG,YAAY,CAAC;AAClD,CAAC;AAED;;;;GAIG;AACH,SAAgB,eAAe;IAC7B,IAAI,CAAC,gBAAK,CAAC,0BAA0B,EAAE,CAAC;QACtC,gBAAK,CAAC,0BAA0B,GAAG,yBAAyB,EAAE,CAAC;IACjE,CAAC;IACD,OAAO,gBAAK,CAAC,0BAA0B,CAAC;AAC1C,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport {\n Instrumenter,\n InstrumenterSpanOptions,\n TracingContext,\n TracingSpan,\n} from \"./interfaces.js\";\n\nimport { createTracingContext } from \"./tracingContext.js\";\nimport { state } from \"./state.js\";\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 addEvent: () => {\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/**\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 state.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 (!state.instrumenterImplementation) {\n state.instrumenterImplementation = createDefaultInstrumenter();\n }\n return state.instrumenterImplementation;\n}\n"]}

View File

@@ -0,0 +1,286 @@
/**
* A narrower version of TypeScript 4.5's Awaited type which Recursively
* unwraps the "awaited type", emulating the behavior of `await`.
*/
export type Resolved<T> = T extends {
then(onfulfilled: infer F): any;
} ? F extends (value: infer V) => any ? Resolved<V> : never : T;
/**
* Represents a client that can integrate with the currently configured {@link Instrumenter}.
*
* Create an instance using {@link createTracingClient}.
*/
export interface TracingClient {
/**
* Wraps a callback in a tracing span, calls the callback, and closes the span.
*
* This is the primary interface for using Tracing and will handle error recording as well as setting the status on the span.
*
* Both synchronous and asynchronous functions will be awaited in order to reflect the result of the callback on the span.
*
* Example:
*
* ```ts snippet:with_span_example
* import { createTracingClient } from "@azure/core-tracing";
*
* const tracingClient = createTracingClient({
* namespace: "test.namespace",
* packageName: "test-package",
* packageVersion: "1.0.0",
* });
* const options = {};
* const myOperationResult = await tracingClient.withSpan(
* "myClassName.myOperationName",
* options,
* (updatedOptions) => {
* // Do something with the updated options.
* return "myOperationResult";
* },
* );
* ```
* @param name - The name of the span. By convention this should be `${className}.${methodName}`.
* @param operationOptions - The original options passed to the method. The callback will receive these options with the newly created {@link TracingContext}.
* @param callback - The callback to be invoked with the updated options and newly created {@link TracingSpan}.
*/
withSpan<Options extends {
tracingOptions?: OperationTracingOptions;
}, Callback extends (updatedOptions: Options, span: Omit<TracingSpan, "end">) => ReturnType<Callback>>(name: string, operationOptions: Options, callback: Callback, spanOptions?: TracingSpanOptions): Promise<Resolved<ReturnType<Callback>>>;
/**
* Starts a given span but does not set it as the active span.
*
* You must end the span using {@link TracingSpan.end}.
*
* Most of the time you will want to use {@link withSpan} instead.
*
* @param name - The name of the span. By convention this should be `${className}.${methodName}`.
* @param operationOptions - The original operation options.
* @param spanOptions - The options to use when creating the span.
*
* @returns A {@link TracingSpan} and the updated operation options.
*/
startSpan<Options extends {
tracingOptions?: OperationTracingOptions;
}>(name: string, operationOptions?: Options, spanOptions?: TracingSpanOptions): {
span: TracingSpan;
updatedOptions: OptionsWithTracingContext<Options>;
};
/**
* Wraps a callback with an active context and calls the callback.
* Depending on the implementation, this may set the globally available active context.
*
* 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.
*
* @param context - The {@link TracingContext} to use as the active context in the scope of the callback.
* @param callback - The callback to be invoked with the given context set as the globally active context.
* @param callbackArgs - The callback arguments.
*/
withContext<CallbackArgs extends unknown[], Callback extends (...args: CallbackArgs) => ReturnType<Callback>>(context: TracingContext, callback: Callback, ...callbackArgs: CallbackArgs): ReturnType<Callback>;
/**
* Parses a traceparent header value into a {@link TracingSpanContext}.
*
* @param traceparentHeader - The traceparent header to parse.
* @returns An implementation-specific identifier for the span.
*/
parseTraceparentHeader(traceparentHeader: string): TracingContext | undefined;
/**
* Creates a set of request headers to propagate tracing information to a backend.
*
* @param tracingContext - The context containing the span to propagate.
* @returns The set of headers to add to a request.
*/
createRequestHeaders(tracingContext?: TracingContext): Record<string, string>;
}
/**
* Options that can be passed to {@link createTracingClient}
*/
export interface TracingClientOptions {
/** The value of the az.namespace tracing attribute on newly created spans. */
namespace: string;
/** The name of the package invoking this trace. */
packageName: string;
/** An optional version of the package invoking this trace. */
packageVersion?: string;
}
/** The kind of span. */
export type TracingSpanKind = "client" | "server" | "producer" | "consumer" | "internal";
/** Options used to configure the newly created span. */
export interface TracingSpanOptions {
/** The kind of span. Implementations should default this to "client". */
spanKind?: TracingSpanKind;
/** A collection of {@link TracingSpanLink} to link to this span. */
spanLinks?: TracingSpanLink[];
/** Initial set of attributes to set on a span. */
spanAttributes?: {
[key: string]: unknown;
};
}
/** A pointer from the current {@link TracingSpan} to another span in the same or a different trace. */
export interface TracingSpanLink {
/** The {@link TracingContext} containing the span context to link to. */
tracingContext: TracingContext;
/** A set of attributes on the link. */
attributes?: {
[key: string]: unknown;
};
}
/**
* Represents an implementation agnostic instrumenter.
*/
export interface Instrumenter {
/**
* Creates a new {@link TracingSpan} with the given name and options and sets it on a new context.
* @param name - The name of the span. By convention this should be `${className}.${methodName}`.
* @param spanOptions - The options to use when creating the span.
*
* @returns A {@link TracingSpan} that can be used to end the span, and the context this span has been set on.
*/
startSpan(name: string, spanOptions: InstrumenterSpanOptions): {
span: TracingSpan;
tracingContext: TracingContext;
};
/**
* Wraps a callback with an active context and calls the callback.
* Depending on the implementation, this may set the globally available active context.
*
* @param context - The {@link TracingContext} to use as the active context in the scope of the callback.
* @param callback - The callback to be invoked with the given context set as the globally active context.
* @param callbackArgs - The callback arguments.
*/
withContext<CallbackArgs extends unknown[], Callback extends (...args: CallbackArgs) => ReturnType<Callback>>(context: TracingContext, callback: Callback, ...callbackArgs: CallbackArgs): ReturnType<Callback>;
/**
* Provides an implementation-specific method to parse a {@link https://www.w3.org/TR/trace-context/#traceparent-header}
* into a {@link TracingSpanContext} which can be used to link non-parented spans together.
*/
parseTraceparentHeader(traceparentHeader: string): TracingContext | undefined;
/**
* Provides an implementation-specific method to serialize a {@link TracingSpan} to a set of headers.
* @param tracingContext - The context containing the span to serialize.
*/
createRequestHeaders(tracingContext?: TracingContext): Record<string, string>;
}
/**
* Options passed to {@link Instrumenter.startSpan} as a superset of {@link TracingSpanOptions}.
*/
export interface InstrumenterSpanOptions extends TracingSpanOptions {
/** The name of the package invoking this trace. */
packageName: string;
/** The version of the package invoking this trace. */
packageVersion?: string;
/** The current tracing context. Defaults to an implementation-specific "active" context. */
tracingContext?: TracingContext;
}
/**
* Status representing a successful operation that can be sent to {@link TracingSpan.setStatus}
*/
export type SpanStatusSuccess = {
status: "success";
};
/**
* Status representing an error that can be sent to {@link TracingSpan.setStatus}
*/
export type SpanStatusError = {
status: "error";
error?: Error | string;
};
/**
* Represents the statuses that can be passed to {@link TracingSpan.setStatus}.
*
* By default, all spans will be created with status "unset".
*/
export type SpanStatus = SpanStatusSuccess | SpanStatusError;
/**
* Represents options you can pass to {@link TracingSpan.addEvent}.
*/
export interface AddEventOptions {
/**
* A set of attributes to attach to the event.
*/
attributes?: Record<string, unknown>;
/**
* The start time of the event.
*/
startTime?: Date;
}
/**
* Represents an implementation agnostic tracing span.
*/
export interface TracingSpan {
/**
* Sets the status of the span. When an error is provided, it will be recorded on the span as well.
*
* @param status - The {@link SpanStatus} to set on the span.
*/
setStatus(status: SpanStatus): void;
/**
* Sets a given attribute on a span.
*
* @param name - The attribute's name.
* @param value - The attribute's value to set. May be any non-nullish value.
*/
setAttribute(name: string, value: unknown): void;
/**
* Ends the span.
*/
end(): void;
/**
* Records an exception on a {@link TracingSpan} without modifying its status.
*
* When recording an unhandled exception that should fail the span, please use {@link TracingSpan.setStatus} instead.
*
* @param exception - The exception to record on the span.
*
*/
recordException(exception: Error | string): void;
/**
* Returns true if this {@link TracingSpan} is recording information.
*
* Depending on the span implementation, this may return false if the span is not being sampled.
*/
isRecording(): boolean;
/**
* Adds an event to the span.
*/
addEvent?(name: string, options?: AddEventOptions): void;
}
/** An immutable context bag of tracing values for the current operation. */
export interface TracingContext {
/**
* Sets a given object on a context.
* @param key - The key of the given context value.
* @param value - The value to set on the context.
*
* @returns - A new context with the given value set.
*/
setValue(key: symbol, value: unknown): TracingContext;
/**
* Gets an object from the context if it exists.
* @param key - The key of the given context value.
*
* @returns - The value of the given context value if it exists, otherwise `undefined`.
*/
getValue(key: symbol): unknown;
/**
* Deletes an object from the context if it exists.
* @param key - The key of the given context value to delete.
*/
deleteValue(key: symbol): TracingContext;
}
/**
* Tracing options to set on an operation.
*/
export interface OperationTracingOptions {
/** The context to use for created Tracing Spans. */
tracingContext?: TracingContext;
}
/**
* A utility type for when we know a TracingContext has been set
* as part of an operation's options.
*/
export type OptionsWithTracingContext<Options extends {
tracingOptions?: OperationTracingOptions;
}> = Options & {
tracingOptions: {
tracingContext: TracingContext;
};
};
//# sourceMappingURL=interfaces.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"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,IAAI,CAAC;IAEpC;;;;;OAKG;IACH,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;IAEjD;;OAEG;IACH,GAAG,IAAI,IAAI,CAAC;IAEZ;;;;;;;OAOG;IACH,eAAe,CAAC,SAAS,EAAE,KAAK,GAAG,MAAM,GAAG,IAAI,CAAC;IAEjD;;;;OAIG;IACH,WAAW,IAAI,OAAO,CAAC;IAEvB;;OAEG;IACH,QAAQ,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,IAAI,CAAC;CAC1D;AAED,4EAA4E;AAC5E,MAAM,WAAW,cAAc;IAC7B;;;;;;OAMG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,cAAc,CAAC;IACtD;;;;;OAKG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;IAC/B;;;OAGG;IACH,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,CAAC;CAC1C;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,oDAAoD;IACpD,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC;AAED;;;GAGG;AACH,MAAM,MAAM,yBAAyB,CACnC,OAAO,SAAS;IAAE,cAAc,CAAC,EAAE,uBAAuB,CAAA;CAAE,IAC1D,OAAO,GAAG;IACZ,cAAc,EAAE;QACd,cAAc,EAAE,cAAc,CAAC;KAChC,CAAC;CACH,CAAC"}

View File

@@ -0,0 +1,5 @@
"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=interfaces.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,3 @@
{
"type": "commonjs"
}

View File

@@ -0,0 +1 @@
{"version":3,"file":"state-cjs.cjs","sourceRoot":"","sources":["../../src/state-cjs.cts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC;;;;GAIG;AACU,QAAA,KAAK,GAAG;IACnB,0BAA0B,EAAE,SAAS;CACtC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * @internal\n *\n * Holds the singleton instrumenter, to be shared across CJS and ESM imports.\n */\nexport const state = {\n instrumenterImplementation: undefined,\n};\n"]}

View File

@@ -0,0 +1 @@
{"version":3,"file":"state-cjs.d.cts","sourceRoot":"","sources":["../../src/state-cjs.cts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,eAAO,MAAM,KAAK;;CAEjB,CAAC"}

View File

@@ -0,0 +1,9 @@
/**
* @internal
*
* Holds the singleton instrumenter, to be shared across CJS and ESM imports.
*/
export declare const state: {
instrumenterImplementation: undefined;
};
//# sourceMappingURL=state-cjs.d.cts.map

View File

@@ -0,0 +1,14 @@
"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.state = void 0;
/**
* @internal
*
* Holds the singleton instrumenter, to be shared across CJS and ESM imports.
*/
exports.state = {
instrumenterImplementation: undefined,
};
//# sourceMappingURL=state-cjs.cjs.map

View File

@@ -0,0 +1,9 @@
import { TracingClient, TracingClientOptions } from "./interfaces.js";
/**
* Creates a new tracing client.
*
* @param options - Options used to configure the tracing client.
* @returns - An instance of {@link TracingClient}.
*/
export declare function createTracingClient(options: TracingClientOptions): TracingClient;
//# sourceMappingURL=tracingClient.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"tracingClient.d.ts","sourceRoot":"","sources":["../../src/tracingClient.ts"],"names":[],"mappings":"AAGA,OAAO,EAIL,aAAa,EACb,oBAAoB,EAIrB,MAAM,iBAAiB,CAAC;AAIzB;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,GAAG,aAAa,CAkGhF"}

View File

@@ -0,0 +1,77 @@
"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.createTracingClient = createTracingClient;
const instrumenter_js_1 = require("./instrumenter.js");
const tracingContext_js_1 = require("./tracingContext.js");
/**
* Creates a new tracing client.
*
* @param options - Options used to configure the tracing client.
* @returns - An instance of {@link TracingClient}.
*/
function createTracingClient(options) {
const { namespace, packageName, packageVersion } = options;
function startSpan(name, operationOptions, spanOptions) {
var _a;
const startSpanResult = (0, instrumenter_js_1.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 }));
let tracingContext = startSpanResult.tracingContext;
const span = startSpanResult.span;
if (!tracingContext.getValue(tracingContext_js_1.knownContextKeys.namespace)) {
tracingContext = tracingContext.setValue(tracingContext_js_1.knownContextKeys.namespace, namespace);
}
span.setAttribute("az.namespace", tracingContext.getValue(tracingContext_js_1.knownContextKeys.namespace));
const updatedOptions = Object.assign({}, operationOptions, {
tracingOptions: Object.assign(Object.assign({}, operationOptions === null || operationOptions === void 0 ? void 0 : operationOptions.tracingOptions), { tracingContext }),
});
return {
span,
updatedOptions,
};
}
async function withSpan(name, operationOptions, callback, spanOptions) {
const { span, updatedOptions } = startSpan(name, operationOptions, spanOptions);
try {
const result = await withContext(updatedOptions.tracingOptions.tracingContext, () => Promise.resolve(callback(updatedOptions, span)));
span.setStatus({ status: "success" });
return result;
}
catch (err) {
span.setStatus({ status: "error", error: err });
throw err;
}
finally {
span.end();
}
}
function withContext(context, callback, ...callbackArgs) {
return (0, instrumenter_js_1.getInstrumenter)().withContext(context, callback, ...callbackArgs);
}
/**
* Parses a traceparent header value into a span identifier.
*
* @param traceparentHeader - The traceparent header to parse.
* @returns An implementation-specific identifier for the span.
*/
function parseTraceparentHeader(traceparentHeader) {
return (0, instrumenter_js_1.getInstrumenter)().parseTraceparentHeader(traceparentHeader);
}
/**
* Creates a set of request headers to propagate tracing information to a backend.
*
* @param tracingContext - The context containing the span to serialize.
* @returns The set of headers to add to a request.
*/
function createRequestHeaders(tracingContext) {
return (0, instrumenter_js_1.getInstrumenter)().createRequestHeaders(tracingContext);
}
return {
startSpan,
withSpan,
withContext,
parseTraceparentHeader,
createRequestHeaders,
};
}
//# sourceMappingURL=tracingClient.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,34 @@
import { TracingContext, TracingSpan } from "./interfaces.js";
/** @internal */
export declare const knownContextKeys: {
span: symbol;
namespace: symbol;
};
/**
* Creates a new {@link TracingContext} with the given options.
* @param options - A set of known keys that may be set on the context.
* @returns A new {@link TracingContext} with the given options.
*
* @internal
*/
export declare function createTracingContext(options?: CreateTracingContextOptions): TracingContext;
/** @internal */
export declare class TracingContextImpl implements TracingContext {
private _contextMap;
constructor(initialContext?: TracingContext);
setValue(key: symbol, value: unknown): TracingContext;
getValue(key: symbol): unknown;
deleteValue(key: symbol): TracingContext;
}
/**
* Represents a set of items that can be set when creating a new {@link TracingContext}.
*/
export interface CreateTracingContextOptions {
/** The {@link parentContext} - the newly created context will contain all the values of the parent context unless overridden. */
parentContext?: TracingContext;
/** An initial span to set on the context. */
span?: TracingSpan;
/** The namespace to set on any child spans. */
namespace?: string;
}
//# sourceMappingURL=tracingContext.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"tracingContext.d.ts","sourceRoot":"","sources":["../../src/tracingContext.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9D,gBAAgB;AAChB,eAAO,MAAM,gBAAgB;;;CAG5B,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,GAAE,2BAAgC,GAAG,cAAc,CAS9F;AAED,gBAAgB;AAChB,qBAAa,kBAAmB,YAAW,cAAc;IACvD,OAAO,CAAC,WAAW,CAAuB;gBAC9B,cAAc,CAAC,EAAE,cAAc;IAO3C,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,cAAc;IAMrD,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAI9B,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc;CAKzC;AAED;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C,iIAAiI;IACjI,aAAa,CAAC,EAAE,cAAc,CAAC;IAC/B,6CAA6C;IAC7C,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,+CAA+C;IAC/C,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB"}

View File

@@ -0,0 +1,52 @@
"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.TracingContextImpl = exports.knownContextKeys = void 0;
exports.createTracingContext = createTracingContext;
/** @internal */
exports.knownContextKeys = {
span: Symbol.for("@azure/core-tracing span"),
namespace: Symbol.for("@azure/core-tracing namespace"),
};
/**
* Creates a new {@link TracingContext} with the given options.
* @param options - A set of known keys that may be set on the context.
* @returns A new {@link TracingContext} with the given options.
*
* @internal
*/
function createTracingContext(options = {}) {
let context = new TracingContextImpl(options.parentContext);
if (options.span) {
context = context.setValue(exports.knownContextKeys.span, options.span);
}
if (options.namespace) {
context = context.setValue(exports.knownContextKeys.namespace, options.namespace);
}
return context;
}
/** @internal */
class TracingContextImpl {
constructor(initialContext) {
this._contextMap =
initialContext instanceof TracingContextImpl
? new Map(initialContext._contextMap)
: new Map();
}
setValue(key, value) {
const newContext = new TracingContextImpl(this);
newContext._contextMap.set(key, value);
return newContext;
}
getValue(key) {
return this._contextMap.get(key);
}
deleteValue(key) {
const newContext = new TracingContextImpl(this);
newContext._contextMap.delete(key);
return newContext;
}
}
exports.TracingContextImpl = TracingContextImpl;
//# sourceMappingURL=tracingContext.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"tracingContext.js","sourceRoot":"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AAG,CAAC,CAAC;IACnC,CAAC;IAED,WAAW,CAAC,GAAW;QACrB,MAAM,UAAU,GAAG,IAAI,kBAAkB,CAAC,IAAI,CAAC,CAAC;QAChD,UAAU,CAAC,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACnC,OAAO,UAAU,CAAC;IACpB,CAAC;CACF;AAxBD,gDAwBC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { TracingContext, TracingSpan } from \"./interfaces.js\";\n\n/** @internal */\nexport const knownContextKeys = {\n span: Symbol.for(\"@azure/core-tracing span\"),\n namespace: Symbol.for(\"@azure/core-tracing namespace\"),\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.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 overridden. */\n parentContext?: TracingContext;\n /** An initial span to set on the context. */\n span?: TracingSpan;\n /** The namespace to set on any child spans. */\n namespace?: string;\n}\n"]}

View File

@@ -0,0 +1,11 @@
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
// It should be published with your NPM package. It should not be tracked by Git.
{
"tsdocVersion": "0.12",
"toolPackages": [
{
"packageName": "@microsoft/api-extractor",
"packageVersion": "7.47.9"
}
]
}

317
node_modules/@azure/core-tracing/dist/core-tracing.d.ts generated vendored Normal file
View File

@@ -0,0 +1,317 @@
/**
* Represents options you can pass to {@link TracingSpan.addEvent}.
*/
export declare interface AddEventOptions {
/**
* A set of attributes to attach to the event.
*/
attributes?: Record<string, unknown>;
/**
* The start time of the event.
*/
startTime?: Date;
}
/**
* Creates a new tracing client.
*
* @param options - Options used to configure the tracing client.
* @returns - An instance of {@link TracingClient}.
*/
export declare function createTracingClient(options: TracingClientOptions): TracingClient;
/**
* Represents an implementation agnostic instrumenter.
*/
export declare interface Instrumenter {
/**
* Creates a new {@link TracingSpan} with the given name and options and sets it on a new context.
* @param name - The name of the span. By convention this should be `${className}.${methodName}`.
* @param spanOptions - The options to use when creating the span.
*
* @returns A {@link TracingSpan} that can be used to end the span, and the context this span has been set on.
*/
startSpan(name: string, spanOptions: InstrumenterSpanOptions): {
span: TracingSpan;
tracingContext: TracingContext;
};
/**
* Wraps a callback with an active context and calls the callback.
* Depending on the implementation, this may set the globally available active context.
*
* @param context - The {@link TracingContext} to use as the active context in the scope of the callback.
* @param callback - The callback to be invoked with the given context set as the globally active context.
* @param callbackArgs - The callback arguments.
*/
withContext<CallbackArgs extends unknown[], Callback extends (...args: CallbackArgs) => ReturnType<Callback>>(context: TracingContext, callback: Callback, ...callbackArgs: CallbackArgs): ReturnType<Callback>;
/**
* Provides an implementation-specific method to parse a {@link https://www.w3.org/TR/trace-context/#traceparent-header}
* into a {@link TracingSpanContext} which can be used to link non-parented spans together.
*/
parseTraceparentHeader(traceparentHeader: string): TracingContext | undefined;
/**
* Provides an implementation-specific method to serialize a {@link TracingSpan} to a set of headers.
* @param tracingContext - The context containing the span to serialize.
*/
createRequestHeaders(tracingContext?: TracingContext): Record<string, string>;
}
/**
* Options passed to {@link Instrumenter.startSpan} as a superset of {@link TracingSpanOptions}.
*/
export declare interface InstrumenterSpanOptions extends TracingSpanOptions {
/** The name of the package invoking this trace. */
packageName: string;
/** The version of the package invoking this trace. */
packageVersion?: string;
/** The current tracing context. Defaults to an implementation-specific "active" context. */
tracingContext?: TracingContext;
}
/**
* Tracing options to set on an operation.
*/
export declare interface OperationTracingOptions {
/** The context to use for created Tracing Spans. */
tracingContext?: TracingContext;
}
/**
* A utility type for when we know a TracingContext has been set
* as part of an operation's options.
*/
export declare type OptionsWithTracingContext<Options extends {
tracingOptions?: OperationTracingOptions;
}> = Options & {
tracingOptions: {
tracingContext: TracingContext;
};
};
/**
* A narrower version of TypeScript 4.5's Awaited type which Recursively
* unwraps the "awaited type", emulating the behavior of `await`.
*/
export declare type Resolved<T> = T extends {
then(onfulfilled: infer F): any;
} ? F extends (value: infer V) => any ? Resolved<V> : never : T;
/**
* Represents the statuses that can be passed to {@link TracingSpan.setStatus}.
*
* By default, all spans will be created with status "unset".
*/
export declare type SpanStatus = SpanStatusSuccess | SpanStatusError;
/**
* Status representing an error that can be sent to {@link TracingSpan.setStatus}
*/
export declare type SpanStatusError = {
status: "error";
error?: Error | string;
};
/**
* Status representing a successful operation that can be sent to {@link TracingSpan.setStatus}
*/
export declare type SpanStatusSuccess = {
status: "success";
};
/**
* Represents a client that can integrate with the currently configured {@link Instrumenter}.
*
* Create an instance using {@link createTracingClient}.
*/
export declare interface TracingClient {
/**
* Wraps a callback in a tracing span, calls the callback, and closes the span.
*
* This is the primary interface for using Tracing and will handle error recording as well as setting the status on the span.
*
* Both synchronous and asynchronous functions will be awaited in order to reflect the result of the callback on the span.
*
* Example:
*
* ```ts snippet:with_span_example
* import { createTracingClient } from "@azure/core-tracing";
*
* const tracingClient = createTracingClient({
* namespace: "test.namespace",
* packageName: "test-package",
* packageVersion: "1.0.0",
* });
* const options = {};
* const myOperationResult = await tracingClient.withSpan(
* "myClassName.myOperationName",
* options,
* (updatedOptions) => {
* // Do something with the updated options.
* return "myOperationResult";
* },
* );
* ```
* @param name - The name of the span. By convention this should be `${className}.${methodName}`.
* @param operationOptions - The original options passed to the method. The callback will receive these options with the newly created {@link TracingContext}.
* @param callback - The callback to be invoked with the updated options and newly created {@link TracingSpan}.
*/
withSpan<Options extends {
tracingOptions?: OperationTracingOptions;
}, Callback extends (updatedOptions: Options, span: Omit<TracingSpan, "end">) => ReturnType<Callback>>(name: string, operationOptions: Options, callback: Callback, spanOptions?: TracingSpanOptions): Promise<Resolved<ReturnType<Callback>>>;
/**
* Starts a given span but does not set it as the active span.
*
* You must end the span using {@link TracingSpan.end}.
*
* Most of the time you will want to use {@link withSpan} instead.
*
* @param name - The name of the span. By convention this should be `${className}.${methodName}`.
* @param operationOptions - The original operation options.
* @param spanOptions - The options to use when creating the span.
*
* @returns A {@link TracingSpan} and the updated operation options.
*/
startSpan<Options extends {
tracingOptions?: OperationTracingOptions;
}>(name: string, operationOptions?: Options, spanOptions?: TracingSpanOptions): {
span: TracingSpan;
updatedOptions: OptionsWithTracingContext<Options>;
};
/**
* Wraps a callback with an active context and calls the callback.
* Depending on the implementation, this may set the globally available active context.
*
* 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.
*
* @param context - The {@link TracingContext} to use as the active context in the scope of the callback.
* @param callback - The callback to be invoked with the given context set as the globally active context.
* @param callbackArgs - The callback arguments.
*/
withContext<CallbackArgs extends unknown[], Callback extends (...args: CallbackArgs) => ReturnType<Callback>>(context: TracingContext, callback: Callback, ...callbackArgs: CallbackArgs): ReturnType<Callback>;
/**
* Parses a traceparent header value into a {@link TracingSpanContext}.
*
* @param traceparentHeader - The traceparent header to parse.
* @returns An implementation-specific identifier for the span.
*/
parseTraceparentHeader(traceparentHeader: string): TracingContext | undefined;
/**
* Creates a set of request headers to propagate tracing information to a backend.
*
* @param tracingContext - The context containing the span to propagate.
* @returns The set of headers to add to a request.
*/
createRequestHeaders(tracingContext?: TracingContext): Record<string, string>;
}
/**
* Options that can be passed to {@link createTracingClient}
*/
export declare interface TracingClientOptions {
/** The value of the az.namespace tracing attribute on newly created spans. */
namespace: string;
/** The name of the package invoking this trace. */
packageName: string;
/** An optional version of the package invoking this trace. */
packageVersion?: string;
}
/** An immutable context bag of tracing values for the current operation. */
export declare interface TracingContext {
/**
* Sets a given object on a context.
* @param key - The key of the given context value.
* @param value - The value to set on the context.
*
* @returns - A new context with the given value set.
*/
setValue(key: symbol, value: unknown): TracingContext;
/**
* Gets an object from the context if it exists.
* @param key - The key of the given context value.
*
* @returns - The value of the given context value if it exists, otherwise `undefined`.
*/
getValue(key: symbol): unknown;
/**
* Deletes an object from the context if it exists.
* @param key - The key of the given context value to delete.
*/
deleteValue(key: symbol): TracingContext;
}
/**
* Represents an implementation agnostic tracing span.
*/
export declare interface TracingSpan {
/**
* Sets the status of the span. When an error is provided, it will be recorded on the span as well.
*
* @param status - The {@link SpanStatus} to set on the span.
*/
setStatus(status: SpanStatus): void;
/**
* Sets a given attribute on a span.
*
* @param name - The attribute's name.
* @param value - The attribute's value to set. May be any non-nullish value.
*/
setAttribute(name: string, value: unknown): void;
/**
* Ends the span.
*/
end(): void;
/**
* Records an exception on a {@link TracingSpan} without modifying its status.
*
* When recording an unhandled exception that should fail the span, please use {@link TracingSpan.setStatus} instead.
*
* @param exception - The exception to record on the span.
*
*/
recordException(exception: Error | string): void;
/**
* Returns true if this {@link TracingSpan} is recording information.
*
* Depending on the span implementation, this may return false if the span is not being sampled.
*/
isRecording(): boolean;
/**
* Adds an event to the span.
*/
addEvent?(name: string, options?: AddEventOptions): void;
}
/** The kind of span. */
export declare type TracingSpanKind = "client" | "server" | "producer" | "consumer" | "internal";
/** A pointer from the current {@link TracingSpan} to another span in the same or a different trace. */
export declare interface TracingSpanLink {
/** The {@link TracingContext} containing the span context to link to. */
tracingContext: TracingContext;
/** A set of attributes on the link. */
attributes?: {
[key: string]: unknown;
};
}
/** Options used to configure the newly created span. */
export declare interface TracingSpanOptions {
/** The kind of span. Implementations should default this to "client". */
spanKind?: TracingSpanKind;
/** A collection of {@link TracingSpanLink} to link to this span. */
spanLinks?: TracingSpanLink[];
/** Initial set of attributes to set on a span. */
spanAttributes?: {
[key: string]: unknown;
};
}
/**
* Extends the Azure SDK with support for a given instrumenter implementation.
*
* @param instrumenter - The instrumenter implementation to use.
*/
export declare function useInstrumenter(instrumenter: Instrumenter): void;
export { }

4
node_modules/@azure/core-tracing/dist/esm/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,4 @@
export { AddEventOptions, Instrumenter, InstrumenterSpanOptions, OperationTracingOptions, OptionsWithTracingContext, Resolved, SpanStatus, SpanStatusError, SpanStatusSuccess, TracingClient, TracingClientOptions, TracingContext, TracingSpan, TracingSpanKind, TracingSpanLink, TracingSpanOptions, } from "./interfaces.js";
export { useInstrumenter } from "./instrumenter.js";
export { createTracingClient } from "./tracingClient.js";
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,eAAe,EACf,YAAY,EACZ,uBAAuB,EACvB,uBAAuB,EACvB,yBAAyB,EACzB,QAAQ,EACR,UAAU,EACV,eAAe,EACf,iBAAiB,EACjB,aAAa,EACb,oBAAoB,EACpB,cAAc,EACd,WAAW,EACX,eAAe,EACf,eAAe,EACf,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC"}

5
node_modules/@azure/core-tracing/dist/esm/index.js generated vendored Normal file
View File

@@ -0,0 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
export { useInstrumenter } from "./instrumenter.js";
export { createTracingClient } from "./tracingClient.js";
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAoBlC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nexport {\n AddEventOptions,\n Instrumenter,\n InstrumenterSpanOptions,\n OperationTracingOptions,\n OptionsWithTracingContext,\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.js\";\nexport { useInstrumenter } from \"./instrumenter.js\";\nexport { createTracingClient } from \"./tracingClient.js\";\n"]}

View File

@@ -0,0 +1,16 @@
import { Instrumenter, TracingSpan } from "./interfaces.js";
export declare function createDefaultTracingSpan(): TracingSpan;
export declare function createDefaultInstrumenter(): Instrumenter;
/**
* Extends the Azure SDK with support for a given instrumenter implementation.
*
* @param instrumenter - The instrumenter implementation to use.
*/
export declare function useInstrumenter(instrumenter: Instrumenter): void;
/**
* Gets the currently set instrumenter, a No-Op instrumenter by default.
*
* @returns The currently set instrumenter
*/
export declare function getInstrumenter(): Instrumenter;
//# sourceMappingURL=instrumenter.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"instrumenter.d.ts","sourceRoot":"","sources":["../../src/instrumenter.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,YAAY,EAGZ,WAAW,EACZ,MAAM,iBAAiB,CAAC;AAKzB,wBAAgB,wBAAwB,IAAI,WAAW,CAmBtD;AAED,wBAAgB,yBAAyB,IAAI,YAAY,CA4BxD;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,YAAY,EAAE,YAAY,GAAG,IAAI,CAEhE;AAED;;;;GAIG;AACH,wBAAgB,eAAe,IAAI,YAAY,CAK9C"}

View File

@@ -0,0 +1,63 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { createTracingContext } from "./tracingContext.js";
import { state } from "./state.js";
export function createDefaultTracingSpan() {
return {
end: () => {
// noop
},
isRecording: () => false,
recordException: () => {
// noop
},
setAttribute: () => {
// noop
},
setStatus: () => {
// noop
},
addEvent: () => {
// noop
},
};
}
export function createDefaultInstrumenter() {
return {
createRequestHeaders: () => {
return {};
},
parseTraceparentHeader: () => {
return undefined;
},
startSpan: (_name, spanOptions) => {
return {
span: createDefaultTracingSpan(),
tracingContext: createTracingContext({ parentContext: spanOptions.tracingContext }),
};
},
withContext(_context, callback, ...callbackArgs) {
return callback(...callbackArgs);
},
};
}
/**
* Extends the Azure SDK with support for a given instrumenter implementation.
*
* @param instrumenter - The instrumenter implementation to use.
*/
export function useInstrumenter(instrumenter) {
state.instrumenterImplementation = instrumenter;
}
/**
* Gets the currently set instrumenter, a No-Op instrumenter by default.
*
* @returns The currently set instrumenter
*/
export function getInstrumenter() {
if (!state.instrumenterImplementation) {
state.instrumenterImplementation = createDefaultInstrumenter();
}
return state.instrumenterImplementation;
}
//# sourceMappingURL=instrumenter.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"instrumenter.js","sourceRoot":"","sources":["../../src/instrumenter.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AASlC,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,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;QACD,QAAQ,EAAE,GAAG,EAAE;YACb,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;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,YAA0B;IACxD,KAAK,CAAC,0BAA0B,GAAG,YAAY,CAAC;AAClD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe;IAC7B,IAAI,CAAC,KAAK,CAAC,0BAA0B,EAAE,CAAC;QACtC,KAAK,CAAC,0BAA0B,GAAG,yBAAyB,EAAE,CAAC;IACjE,CAAC;IACD,OAAO,KAAK,CAAC,0BAA0B,CAAC;AAC1C,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport {\n Instrumenter,\n InstrumenterSpanOptions,\n TracingContext,\n TracingSpan,\n} from \"./interfaces.js\";\n\nimport { createTracingContext } from \"./tracingContext.js\";\nimport { state } from \"./state.js\";\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 addEvent: () => {\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/**\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 state.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 (!state.instrumenterImplementation) {\n state.instrumenterImplementation = createDefaultInstrumenter();\n }\n return state.instrumenterImplementation;\n}\n"]}

View File

@@ -0,0 +1,286 @@
/**
* A narrower version of TypeScript 4.5's Awaited type which Recursively
* unwraps the "awaited type", emulating the behavior of `await`.
*/
export type Resolved<T> = T extends {
then(onfulfilled: infer F): any;
} ? F extends (value: infer V) => any ? Resolved<V> : never : T;
/**
* Represents a client that can integrate with the currently configured {@link Instrumenter}.
*
* Create an instance using {@link createTracingClient}.
*/
export interface TracingClient {
/**
* Wraps a callback in a tracing span, calls the callback, and closes the span.
*
* This is the primary interface for using Tracing and will handle error recording as well as setting the status on the span.
*
* Both synchronous and asynchronous functions will be awaited in order to reflect the result of the callback on the span.
*
* Example:
*
* ```ts snippet:with_span_example
* import { createTracingClient } from "@azure/core-tracing";
*
* const tracingClient = createTracingClient({
* namespace: "test.namespace",
* packageName: "test-package",
* packageVersion: "1.0.0",
* });
* const options = {};
* const myOperationResult = await tracingClient.withSpan(
* "myClassName.myOperationName",
* options,
* (updatedOptions) => {
* // Do something with the updated options.
* return "myOperationResult";
* },
* );
* ```
* @param name - The name of the span. By convention this should be `${className}.${methodName}`.
* @param operationOptions - The original options passed to the method. The callback will receive these options with the newly created {@link TracingContext}.
* @param callback - The callback to be invoked with the updated options and newly created {@link TracingSpan}.
*/
withSpan<Options extends {
tracingOptions?: OperationTracingOptions;
}, Callback extends (updatedOptions: Options, span: Omit<TracingSpan, "end">) => ReturnType<Callback>>(name: string, operationOptions: Options, callback: Callback, spanOptions?: TracingSpanOptions): Promise<Resolved<ReturnType<Callback>>>;
/**
* Starts a given span but does not set it as the active span.
*
* You must end the span using {@link TracingSpan.end}.
*
* Most of the time you will want to use {@link withSpan} instead.
*
* @param name - The name of the span. By convention this should be `${className}.${methodName}`.
* @param operationOptions - The original operation options.
* @param spanOptions - The options to use when creating the span.
*
* @returns A {@link TracingSpan} and the updated operation options.
*/
startSpan<Options extends {
tracingOptions?: OperationTracingOptions;
}>(name: string, operationOptions?: Options, spanOptions?: TracingSpanOptions): {
span: TracingSpan;
updatedOptions: OptionsWithTracingContext<Options>;
};
/**
* Wraps a callback with an active context and calls the callback.
* Depending on the implementation, this may set the globally available active context.
*
* 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.
*
* @param context - The {@link TracingContext} to use as the active context in the scope of the callback.
* @param callback - The callback to be invoked with the given context set as the globally active context.
* @param callbackArgs - The callback arguments.
*/
withContext<CallbackArgs extends unknown[], Callback extends (...args: CallbackArgs) => ReturnType<Callback>>(context: TracingContext, callback: Callback, ...callbackArgs: CallbackArgs): ReturnType<Callback>;
/**
* Parses a traceparent header value into a {@link TracingSpanContext}.
*
* @param traceparentHeader - The traceparent header to parse.
* @returns An implementation-specific identifier for the span.
*/
parseTraceparentHeader(traceparentHeader: string): TracingContext | undefined;
/**
* Creates a set of request headers to propagate tracing information to a backend.
*
* @param tracingContext - The context containing the span to propagate.
* @returns The set of headers to add to a request.
*/
createRequestHeaders(tracingContext?: TracingContext): Record<string, string>;
}
/**
* Options that can be passed to {@link createTracingClient}
*/
export interface TracingClientOptions {
/** The value of the az.namespace tracing attribute on newly created spans. */
namespace: string;
/** The name of the package invoking this trace. */
packageName: string;
/** An optional version of the package invoking this trace. */
packageVersion?: string;
}
/** The kind of span. */
export type TracingSpanKind = "client" | "server" | "producer" | "consumer" | "internal";
/** Options used to configure the newly created span. */
export interface TracingSpanOptions {
/** The kind of span. Implementations should default this to "client". */
spanKind?: TracingSpanKind;
/** A collection of {@link TracingSpanLink} to link to this span. */
spanLinks?: TracingSpanLink[];
/** Initial set of attributes to set on a span. */
spanAttributes?: {
[key: string]: unknown;
};
}
/** A pointer from the current {@link TracingSpan} to another span in the same or a different trace. */
export interface TracingSpanLink {
/** The {@link TracingContext} containing the span context to link to. */
tracingContext: TracingContext;
/** A set of attributes on the link. */
attributes?: {
[key: string]: unknown;
};
}
/**
* Represents an implementation agnostic instrumenter.
*/
export interface Instrumenter {
/**
* Creates a new {@link TracingSpan} with the given name and options and sets it on a new context.
* @param name - The name of the span. By convention this should be `${className}.${methodName}`.
* @param spanOptions - The options to use when creating the span.
*
* @returns A {@link TracingSpan} that can be used to end the span, and the context this span has been set on.
*/
startSpan(name: string, spanOptions: InstrumenterSpanOptions): {
span: TracingSpan;
tracingContext: TracingContext;
};
/**
* Wraps a callback with an active context and calls the callback.
* Depending on the implementation, this may set the globally available active context.
*
* @param context - The {@link TracingContext} to use as the active context in the scope of the callback.
* @param callback - The callback to be invoked with the given context set as the globally active context.
* @param callbackArgs - The callback arguments.
*/
withContext<CallbackArgs extends unknown[], Callback extends (...args: CallbackArgs) => ReturnType<Callback>>(context: TracingContext, callback: Callback, ...callbackArgs: CallbackArgs): ReturnType<Callback>;
/**
* Provides an implementation-specific method to parse a {@link https://www.w3.org/TR/trace-context/#traceparent-header}
* into a {@link TracingSpanContext} which can be used to link non-parented spans together.
*/
parseTraceparentHeader(traceparentHeader: string): TracingContext | undefined;
/**
* Provides an implementation-specific method to serialize a {@link TracingSpan} to a set of headers.
* @param tracingContext - The context containing the span to serialize.
*/
createRequestHeaders(tracingContext?: TracingContext): Record<string, string>;
}
/**
* Options passed to {@link Instrumenter.startSpan} as a superset of {@link TracingSpanOptions}.
*/
export interface InstrumenterSpanOptions extends TracingSpanOptions {
/** The name of the package invoking this trace. */
packageName: string;
/** The version of the package invoking this trace. */
packageVersion?: string;
/** The current tracing context. Defaults to an implementation-specific "active" context. */
tracingContext?: TracingContext;
}
/**
* Status representing a successful operation that can be sent to {@link TracingSpan.setStatus}
*/
export type SpanStatusSuccess = {
status: "success";
};
/**
* Status representing an error that can be sent to {@link TracingSpan.setStatus}
*/
export type SpanStatusError = {
status: "error";
error?: Error | string;
};
/**
* Represents the statuses that can be passed to {@link TracingSpan.setStatus}.
*
* By default, all spans will be created with status "unset".
*/
export type SpanStatus = SpanStatusSuccess | SpanStatusError;
/**
* Represents options you can pass to {@link TracingSpan.addEvent}.
*/
export interface AddEventOptions {
/**
* A set of attributes to attach to the event.
*/
attributes?: Record<string, unknown>;
/**
* The start time of the event.
*/
startTime?: Date;
}
/**
* Represents an implementation agnostic tracing span.
*/
export interface TracingSpan {
/**
* Sets the status of the span. When an error is provided, it will be recorded on the span as well.
*
* @param status - The {@link SpanStatus} to set on the span.
*/
setStatus(status: SpanStatus): void;
/**
* Sets a given attribute on a span.
*
* @param name - The attribute's name.
* @param value - The attribute's value to set. May be any non-nullish value.
*/
setAttribute(name: string, value: unknown): void;
/**
* Ends the span.
*/
end(): void;
/**
* Records an exception on a {@link TracingSpan} without modifying its status.
*
* When recording an unhandled exception that should fail the span, please use {@link TracingSpan.setStatus} instead.
*
* @param exception - The exception to record on the span.
*
*/
recordException(exception: Error | string): void;
/**
* Returns true if this {@link TracingSpan} is recording information.
*
* Depending on the span implementation, this may return false if the span is not being sampled.
*/
isRecording(): boolean;
/**
* Adds an event to the span.
*/
addEvent?(name: string, options?: AddEventOptions): void;
}
/** An immutable context bag of tracing values for the current operation. */
export interface TracingContext {
/**
* Sets a given object on a context.
* @param key - The key of the given context value.
* @param value - The value to set on the context.
*
* @returns - A new context with the given value set.
*/
setValue(key: symbol, value: unknown): TracingContext;
/**
* Gets an object from the context if it exists.
* @param key - The key of the given context value.
*
* @returns - The value of the given context value if it exists, otherwise `undefined`.
*/
getValue(key: symbol): unknown;
/**
* Deletes an object from the context if it exists.
* @param key - The key of the given context value to delete.
*/
deleteValue(key: symbol): TracingContext;
}
/**
* Tracing options to set on an operation.
*/
export interface OperationTracingOptions {
/** The context to use for created Tracing Spans. */
tracingContext?: TracingContext;
}
/**
* A utility type for when we know a TracingContext has been set
* as part of an operation's options.
*/
export type OptionsWithTracingContext<Options extends {
tracingOptions?: OperationTracingOptions;
}> = Options & {
tracingOptions: {
tracingContext: TracingContext;
};
};
//# sourceMappingURL=interfaces.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../src/interfaces.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,CAAC,SAAS;IAAE,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC,GAAG,GAAG,CAAA;CAAE,GACnE,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,GAAG,GAC/B,QAAQ,CAAC,CAAC,CAAC,GACX,KAAK,GACP,CAAC,CAAC;AAEN;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACH,QAAQ,CACN,OAAO,SAAS;QAAE,cAAc,CAAC,EAAE,uBAAuB,CAAA;KAAE,EAC5D,QAAQ,SAAS,CACf,cAAc,EAAE,OAAO,EACvB,IAAI,EAAE,IAAI,CAAC,WAAW,EAAE,KAAK,CA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,EAAE,MAAM,GAAG,OAAO,CAAC;IAC/B;;;OAGG;IACH,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,CAAC;CAC1C;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,oDAAoD;IACpD,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC;AAED;;;GAGG;AACH,MAAM,MAAM,yBAAyB,CACnC,OAAO,SAAS;IAAE,cAAc,CAAC,EAAE,uBAAuB,CAAA;CAAE,IAC1D,OAAO,GAAG;IACZ,cAAc,EAAE;QACd,cAAc,EAAE,cAAc,CAAC;KAChC,CAAC;CACH,CAAC"}

View File

@@ -0,0 +1,4 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
export {};
//# sourceMappingURL=interfaces.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,3 @@
{
"type": "module"
}

8
node_modules/@azure/core-tracing/dist/esm/state.d.ts generated vendored Normal file
View File

@@ -0,0 +1,8 @@
import { Instrumenter } from "./interfaces.js";
/**
* Defines the shared state between CJS and ESM by re-exporting the CJS state.
*/
export declare const state: {
instrumenterImplementation: Instrumenter | undefined;
};
//# sourceMappingURL=state.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/state.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAK/C;;GAEG;AACH,eAAO,MAAM,KAAK,EAAe;IAC/B,0BAA0B,EAAE,YAAY,GAAG,SAAS,CAAC;CACtD,CAAC"}

10
node_modules/@azure/core-tracing/dist/esm/state.js generated vendored Normal file
View File

@@ -0,0 +1,10 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// @ts-expect-error The recommended approach to sharing module state between ESM and CJS.
// See https://github.com/isaacs/tshy/blob/main/README.md#module-local-state for additional information.
import { state as cjsState } from "../commonjs/state.js";
/**
* Defines the shared state between CJS and ESM by re-exporting the CJS state.
*/
export const state = cjsState;
//# sourceMappingURL=state.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/state.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,yFAAyF;AACzF,wGAAwG;AACxG,OAAO,EAAE,KAAK,IAAI,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEzD;;GAEG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,QAEpB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { Instrumenter } from \"./interfaces.js\";\n// @ts-expect-error The recommended approach to sharing module state between ESM and CJS.\n// See https://github.com/isaacs/tshy/blob/main/README.md#module-local-state for additional information.\nimport { state as cjsState } from \"../commonjs/state.js\";\n\n/**\n * Defines the shared state between CJS and ESM by re-exporting the CJS state.\n */\nexport const state = cjsState as {\n instrumenterImplementation: Instrumenter | undefined;\n};\n"]}

View File

@@ -0,0 +1,9 @@
import { TracingClient, TracingClientOptions } from "./interfaces.js";
/**
* Creates a new tracing client.
*
* @param options - Options used to configure the tracing client.
* @returns - An instance of {@link TracingClient}.
*/
export declare function createTracingClient(options: TracingClientOptions): TracingClient;
//# sourceMappingURL=tracingClient.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"tracingClient.d.ts","sourceRoot":"","sources":["../../src/tracingClient.ts"],"names":[],"mappings":"AAGA,OAAO,EAIL,aAAa,EACb,oBAAoB,EAIrB,MAAM,iBAAiB,CAAC;AAIzB;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,GAAG,aAAa,CAkGhF"}

View File

@@ -0,0 +1,74 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { getInstrumenter } from "./instrumenter.js";
import { knownContextKeys } from "./tracingContext.js";
/**
* Creates a new tracing client.
*
* @param options - Options used to configure the tracing client.
* @returns - An instance of {@link TracingClient}.
*/
export function createTracingClient(options) {
const { namespace, packageName, packageVersion } = options;
function startSpan(name, operationOptions, spanOptions) {
var _a;
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 }));
let tracingContext = startSpanResult.tracingContext;
const span = startSpanResult.span;
if (!tracingContext.getValue(knownContextKeys.namespace)) {
tracingContext = tracingContext.setValue(knownContextKeys.namespace, namespace);
}
span.setAttribute("az.namespace", tracingContext.getValue(knownContextKeys.namespace));
const updatedOptions = Object.assign({}, operationOptions, {
tracingOptions: Object.assign(Object.assign({}, operationOptions === null || operationOptions === void 0 ? void 0 : operationOptions.tracingOptions), { tracingContext }),
});
return {
span,
updatedOptions,
};
}
async function withSpan(name, operationOptions, callback, spanOptions) {
const { span, updatedOptions } = startSpan(name, operationOptions, spanOptions);
try {
const result = await withContext(updatedOptions.tracingOptions.tracingContext, () => Promise.resolve(callback(updatedOptions, span)));
span.setStatus({ status: "success" });
return result;
}
catch (err) {
span.setStatus({ status: "error", error: err });
throw err;
}
finally {
span.end();
}
}
function withContext(context, callback, ...callbackArgs) {
return getInstrumenter().withContext(context, callback, ...callbackArgs);
}
/**
* Parses a traceparent header value into a span identifier.
*
* @param traceparentHeader - The traceparent header to parse.
* @returns An implementation-specific identifier for the span.
*/
function parseTraceparentHeader(traceparentHeader) {
return getInstrumenter().parseTraceparentHeader(traceparentHeader);
}
/**
* Creates a set of request headers to propagate tracing information to a backend.
*
* @param tracingContext - The context containing the span to serialize.
* @returns The set of headers to add to a request.
*/
function createRequestHeaders(tracingContext) {
return getInstrumenter().createRequestHeaders(tracingContext);
}
return {
startSpan,
withSpan,
withContext,
parseTraceparentHeader,
createRequestHeaders,
};
}
//# sourceMappingURL=tracingClient.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,34 @@
import { TracingContext, TracingSpan } from "./interfaces.js";
/** @internal */
export declare const knownContextKeys: {
span: symbol;
namespace: symbol;
};
/**
* Creates a new {@link TracingContext} with the given options.
* @param options - A set of known keys that may be set on the context.
* @returns A new {@link TracingContext} with the given options.
*
* @internal
*/
export declare function createTracingContext(options?: CreateTracingContextOptions): TracingContext;
/** @internal */
export declare class TracingContextImpl implements TracingContext {
private _contextMap;
constructor(initialContext?: TracingContext);
setValue(key: symbol, value: unknown): TracingContext;
getValue(key: symbol): unknown;
deleteValue(key: symbol): TracingContext;
}
/**
* Represents a set of items that can be set when creating a new {@link TracingContext}.
*/
export interface CreateTracingContextOptions {
/** The {@link parentContext} - the newly created context will contain all the values of the parent context unless overridden. */
parentContext?: TracingContext;
/** An initial span to set on the context. */
span?: TracingSpan;
/** The namespace to set on any child spans. */
namespace?: string;
}
//# sourceMappingURL=tracingContext.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"tracingContext.d.ts","sourceRoot":"","sources":["../../src/tracingContext.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9D,gBAAgB;AAChB,eAAO,MAAM,gBAAgB;;;CAG5B,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,GAAE,2BAAgC,GAAG,cAAc,CAS9F;AAED,gBAAgB;AAChB,qBAAa,kBAAmB,YAAW,cAAc;IACvD,OAAO,CAAC,WAAW,CAAuB;gBAC9B,cAAc,CAAC,EAAE,cAAc;IAO3C,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,cAAc;IAMrD,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAI9B,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc;CAKzC;AAED;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C,iIAAiI;IACjI,aAAa,CAAC,EAAE,cAAc,CAAC;IAC/B,6CAA6C;IAC7C,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,+CAA+C;IAC/C,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB"}

View File

@@ -0,0 +1,47 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
/** @internal */
export const knownContextKeys = {
span: Symbol.for("@azure/core-tracing span"),
namespace: Symbol.for("@azure/core-tracing namespace"),
};
/**
* Creates a new {@link TracingContext} with the given options.
* @param options - A set of known keys that may be set on the context.
* @returns A new {@link TracingContext} with the given options.
*
* @internal
*/
export function createTracingContext(options = {}) {
let context = new TracingContextImpl(options.parentContext);
if (options.span) {
context = context.setValue(knownContextKeys.span, options.span);
}
if (options.namespace) {
context = context.setValue(knownContextKeys.namespace, options.namespace);
}
return context;
}
/** @internal */
export class TracingContextImpl {
constructor(initialContext) {
this._contextMap =
initialContext instanceof TracingContextImpl
? new Map(initialContext._contextMap)
: new Map();
}
setValue(key, value) {
const newContext = new TracingContextImpl(this);
newContext._contextMap.set(key, value);
return newContext;
}
getValue(key) {
return this._contextMap.get(key);
}
deleteValue(key) {
const newContext = new TracingContextImpl(this);
newContext._contextMap.delete(key);
return newContext;
}
}
//# sourceMappingURL=tracingContext.js.map

View File

@@ -0,0 +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;CACvD,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAAC,UAAuC,EAAE;IAC5E,IAAI,OAAO,GAAmB,IAAI,kBAAkB,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IAC5E,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;QACjB,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAClE,CAAC;IACD,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;QACtB,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAC,SAAS,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IAC5E,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,gBAAgB;AAChB,MAAM,OAAO,kBAAkB;IAE7B,YAAY,cAA+B;QACzC,IAAI,CAAC,WAAW;YACd,cAAc,YAAY,kBAAkB;gBAC1C,CAAC,CAAC,IAAI,GAAG,CAAkB,cAAc,CAAC,WAAW,CAAC;gBACtD,CAAC,CAAC,IAAI,GAAG,EAAE,CAAC;IAClB,CAAC;IAED,QAAQ,CAAC,GAAW,EAAE,KAAc;QAClC,MAAM,UAAU,GAAG,IAAI,kBAAkB,CAAC,IAAI,CAAC,CAAC;QAChD,UAAU,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACvC,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,QAAQ,CAAC,GAAW;QAClB,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACnC,CAAC;IAED,WAAW,CAAC,GAAW;QACrB,MAAM,UAAU,GAAG,IAAI,kBAAkB,CAAC,IAAI,CAAC,CAAC;QAChD,UAAU,CAAC,WAAW,CAAC,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 { TracingContext, TracingSpan } from \"./interfaces.js\";\n\n/** @internal */\nexport const knownContextKeys = {\n span: Symbol.for(\"@azure/core-tracing span\"),\n namespace: Symbol.for(\"@azure/core-tracing namespace\"),\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.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 overridden. */\n parentContext?: TracingContext;\n /** An initial span to set on the context. */\n span?: TracingSpan;\n /** The namespace to set on any child spans. */\n namespace?: string;\n}\n"]}

View File

@@ -0,0 +1,4 @@
export { AddEventOptions, Instrumenter, InstrumenterSpanOptions, OperationTracingOptions, OptionsWithTracingContext, Resolved, SpanStatus, SpanStatusError, SpanStatusSuccess, TracingClient, TracingClientOptions, TracingContext, TracingSpan, TracingSpanKind, TracingSpanLink, TracingSpanOptions, } from "./interfaces.js";
export { useInstrumenter } from "./instrumenter.js";
export { createTracingClient } from "./tracingClient.js";
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,eAAe,EACf,YAAY,EACZ,uBAAuB,EACvB,uBAAuB,EACvB,yBAAyB,EACzB,QAAQ,EACR,UAAU,EACV,eAAe,EACf,iBAAiB,EACjB,aAAa,EACb,oBAAoB,EACpB,cAAc,EACd,WAAW,EACX,eAAe,EACf,eAAe,EACf,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC"}

View File

@@ -0,0 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
export { useInstrumenter } from "./instrumenter.js";
export { createTracingClient } from "./tracingClient.js";
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAoBlC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nexport {\n AddEventOptions,\n Instrumenter,\n InstrumenterSpanOptions,\n OperationTracingOptions,\n OptionsWithTracingContext,\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.js\";\nexport { useInstrumenter } from \"./instrumenter.js\";\nexport { createTracingClient } from \"./tracingClient.js\";\n"]}

View File

@@ -0,0 +1,16 @@
import { Instrumenter, TracingSpan } from "./interfaces.js";
export declare function createDefaultTracingSpan(): TracingSpan;
export declare function createDefaultInstrumenter(): Instrumenter;
/**
* Extends the Azure SDK with support for a given instrumenter implementation.
*
* @param instrumenter - The instrumenter implementation to use.
*/
export declare function useInstrumenter(instrumenter: Instrumenter): void;
/**
* Gets the currently set instrumenter, a No-Op instrumenter by default.
*
* @returns The currently set instrumenter
*/
export declare function getInstrumenter(): Instrumenter;
//# sourceMappingURL=instrumenter.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"instrumenter.d.ts","sourceRoot":"","sources":["../../src/instrumenter.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,YAAY,EAGZ,WAAW,EACZ,MAAM,iBAAiB,CAAC;AAKzB,wBAAgB,wBAAwB,IAAI,WAAW,CAmBtD;AAED,wBAAgB,yBAAyB,IAAI,YAAY,CA4BxD;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,YAAY,EAAE,YAAY,GAAG,IAAI,CAEhE;AAED;;;;GAIG;AACH,wBAAgB,eAAe,IAAI,YAAY,CAK9C"}

View File

@@ -0,0 +1,63 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { createTracingContext } from "./tracingContext.js";
import { state } from "./state.js";
export function createDefaultTracingSpan() {
return {
end: () => {
// noop
},
isRecording: () => false,
recordException: () => {
// noop
},
setAttribute: () => {
// noop
},
setStatus: () => {
// noop
},
addEvent: () => {
// noop
},
};
}
export function createDefaultInstrumenter() {
return {
createRequestHeaders: () => {
return {};
},
parseTraceparentHeader: () => {
return undefined;
},
startSpan: (_name, spanOptions) => {
return {
span: createDefaultTracingSpan(),
tracingContext: createTracingContext({ parentContext: spanOptions.tracingContext }),
};
},
withContext(_context, callback, ...callbackArgs) {
return callback(...callbackArgs);
},
};
}
/**
* Extends the Azure SDK with support for a given instrumenter implementation.
*
* @param instrumenter - The instrumenter implementation to use.
*/
export function useInstrumenter(instrumenter) {
state.instrumenterImplementation = instrumenter;
}
/**
* Gets the currently set instrumenter, a No-Op instrumenter by default.
*
* @returns The currently set instrumenter
*/
export function getInstrumenter() {
if (!state.instrumenterImplementation) {
state.instrumenterImplementation = createDefaultInstrumenter();
}
return state.instrumenterImplementation;
}
//# sourceMappingURL=instrumenter.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"instrumenter.js","sourceRoot":"","sources":["../../src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;QACtC,KAAK,CAAC,0BAA0B,GAAG,yBAAyB,EAAE,CAAC;IACjE,CAAC;IACD,OAAO,KAAK,CAAC,0BAA0B,CAAC;AAC1C,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport {\n Instrumenter,\n InstrumenterSpanOptions,\n TracingContext,\n TracingSpan,\n} from \"./interfaces.js\";\n\nimport { createTracingContext } from \"./tracingContext.js\";\nimport { state } from \"./state.js\";\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 addEvent: () => {\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/**\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 state.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 (!state.instrumenterImplementation) {\n state.instrumenterImplementation = createDefaultInstrumenter();\n }\n return state.instrumenterImplementation;\n}\n"]}

View File

@@ -0,0 +1,286 @@
/**
* A narrower version of TypeScript 4.5's Awaited type which Recursively
* unwraps the "awaited type", emulating the behavior of `await`.
*/
export type Resolved<T> = T extends {
then(onfulfilled: infer F): any;
} ? F extends (value: infer V) => any ? Resolved<V> : never : T;
/**
* Represents a client that can integrate with the currently configured {@link Instrumenter}.
*
* Create an instance using {@link createTracingClient}.
*/
export interface TracingClient {
/**
* Wraps a callback in a tracing span, calls the callback, and closes the span.
*
* This is the primary interface for using Tracing and will handle error recording as well as setting the status on the span.
*
* Both synchronous and asynchronous functions will be awaited in order to reflect the result of the callback on the span.
*
* Example:
*
* ```ts snippet:with_span_example
* import { createTracingClient } from "@azure/core-tracing";
*
* const tracingClient = createTracingClient({
* namespace: "test.namespace",
* packageName: "test-package",
* packageVersion: "1.0.0",
* });
* const options = {};
* const myOperationResult = await tracingClient.withSpan(
* "myClassName.myOperationName",
* options,
* (updatedOptions) => {
* // Do something with the updated options.
* return "myOperationResult";
* },
* );
* ```
* @param name - The name of the span. By convention this should be `${className}.${methodName}`.
* @param operationOptions - The original options passed to the method. The callback will receive these options with the newly created {@link TracingContext}.
* @param callback - The callback to be invoked with the updated options and newly created {@link TracingSpan}.
*/
withSpan<Options extends {
tracingOptions?: OperationTracingOptions;
}, Callback extends (updatedOptions: Options, span: Omit<TracingSpan, "end">) => ReturnType<Callback>>(name: string, operationOptions: Options, callback: Callback, spanOptions?: TracingSpanOptions): Promise<Resolved<ReturnType<Callback>>>;
/**
* Starts a given span but does not set it as the active span.
*
* You must end the span using {@link TracingSpan.end}.
*
* Most of the time you will want to use {@link withSpan} instead.
*
* @param name - The name of the span. By convention this should be `${className}.${methodName}`.
* @param operationOptions - The original operation options.
* @param spanOptions - The options to use when creating the span.
*
* @returns A {@link TracingSpan} and the updated operation options.
*/
startSpan<Options extends {
tracingOptions?: OperationTracingOptions;
}>(name: string, operationOptions?: Options, spanOptions?: TracingSpanOptions): {
span: TracingSpan;
updatedOptions: OptionsWithTracingContext<Options>;
};
/**
* Wraps a callback with an active context and calls the callback.
* Depending on the implementation, this may set the globally available active context.
*
* 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.
*
* @param context - The {@link TracingContext} to use as the active context in the scope of the callback.
* @param callback - The callback to be invoked with the given context set as the globally active context.
* @param callbackArgs - The callback arguments.
*/
withContext<CallbackArgs extends unknown[], Callback extends (...args: CallbackArgs) => ReturnType<Callback>>(context: TracingContext, callback: Callback, ...callbackArgs: CallbackArgs): ReturnType<Callback>;
/**
* Parses a traceparent header value into a {@link TracingSpanContext}.
*
* @param traceparentHeader - The traceparent header to parse.
* @returns An implementation-specific identifier for the span.
*/
parseTraceparentHeader(traceparentHeader: string): TracingContext | undefined;
/**
* Creates a set of request headers to propagate tracing information to a backend.
*
* @param tracingContext - The context containing the span to propagate.
* @returns The set of headers to add to a request.
*/
createRequestHeaders(tracingContext?: TracingContext): Record<string, string>;
}
/**
* Options that can be passed to {@link createTracingClient}
*/
export interface TracingClientOptions {
/** The value of the az.namespace tracing attribute on newly created spans. */
namespace: string;
/** The name of the package invoking this trace. */
packageName: string;
/** An optional version of the package invoking this trace. */
packageVersion?: string;
}
/** The kind of span. */
export type TracingSpanKind = "client" | "server" | "producer" | "consumer" | "internal";
/** Options used to configure the newly created span. */
export interface TracingSpanOptions {
/** The kind of span. Implementations should default this to "client". */
spanKind?: TracingSpanKind;
/** A collection of {@link TracingSpanLink} to link to this span. */
spanLinks?: TracingSpanLink[];
/** Initial set of attributes to set on a span. */
spanAttributes?: {
[key: string]: unknown;
};
}
/** A pointer from the current {@link TracingSpan} to another span in the same or a different trace. */
export interface TracingSpanLink {
/** The {@link TracingContext} containing the span context to link to. */
tracingContext: TracingContext;
/** A set of attributes on the link. */
attributes?: {
[key: string]: unknown;
};
}
/**
* Represents an implementation agnostic instrumenter.
*/
export interface Instrumenter {
/**
* Creates a new {@link TracingSpan} with the given name and options and sets it on a new context.
* @param name - The name of the span. By convention this should be `${className}.${methodName}`.
* @param spanOptions - The options to use when creating the span.
*
* @returns A {@link TracingSpan} that can be used to end the span, and the context this span has been set on.
*/
startSpan(name: string, spanOptions: InstrumenterSpanOptions): {
span: TracingSpan;
tracingContext: TracingContext;
};
/**
* Wraps a callback with an active context and calls the callback.
* Depending on the implementation, this may set the globally available active context.
*
* @param context - The {@link TracingContext} to use as the active context in the scope of the callback.
* @param callback - The callback to be invoked with the given context set as the globally active context.
* @param callbackArgs - The callback arguments.
*/
withContext<CallbackArgs extends unknown[], Callback extends (...args: CallbackArgs) => ReturnType<Callback>>(context: TracingContext, callback: Callback, ...callbackArgs: CallbackArgs): ReturnType<Callback>;
/**
* Provides an implementation-specific method to parse a {@link https://www.w3.org/TR/trace-context/#traceparent-header}
* into a {@link TracingSpanContext} which can be used to link non-parented spans together.
*/
parseTraceparentHeader(traceparentHeader: string): TracingContext | undefined;
/**
* Provides an implementation-specific method to serialize a {@link TracingSpan} to a set of headers.
* @param tracingContext - The context containing the span to serialize.
*/
createRequestHeaders(tracingContext?: TracingContext): Record<string, string>;
}
/**
* Options passed to {@link Instrumenter.startSpan} as a superset of {@link TracingSpanOptions}.
*/
export interface InstrumenterSpanOptions extends TracingSpanOptions {
/** The name of the package invoking this trace. */
packageName: string;
/** The version of the package invoking this trace. */
packageVersion?: string;
/** The current tracing context. Defaults to an implementation-specific "active" context. */
tracingContext?: TracingContext;
}
/**
* Status representing a successful operation that can be sent to {@link TracingSpan.setStatus}
*/
export type SpanStatusSuccess = {
status: "success";
};
/**
* Status representing an error that can be sent to {@link TracingSpan.setStatus}
*/
export type SpanStatusError = {
status: "error";
error?: Error | string;
};
/**
* Represents the statuses that can be passed to {@link TracingSpan.setStatus}.
*
* By default, all spans will be created with status "unset".
*/
export type SpanStatus = SpanStatusSuccess | SpanStatusError;
/**
* Represents options you can pass to {@link TracingSpan.addEvent}.
*/
export interface AddEventOptions {
/**
* A set of attributes to attach to the event.
*/
attributes?: Record<string, unknown>;
/**
* The start time of the event.
*/
startTime?: Date;
}
/**
* Represents an implementation agnostic tracing span.
*/
export interface TracingSpan {
/**
* Sets the status of the span. When an error is provided, it will be recorded on the span as well.
*
* @param status - The {@link SpanStatus} to set on the span.
*/
setStatus(status: SpanStatus): void;
/**
* Sets a given attribute on a span.
*
* @param name - The attribute's name.
* @param value - The attribute's value to set. May be any non-nullish value.
*/
setAttribute(name: string, value: unknown): void;
/**
* Ends the span.
*/
end(): void;
/**
* Records an exception on a {@link TracingSpan} without modifying its status.
*
* When recording an unhandled exception that should fail the span, please use {@link TracingSpan.setStatus} instead.
*
* @param exception - The exception to record on the span.
*
*/
recordException(exception: Error | string): void;
/**
* Returns true if this {@link TracingSpan} is recording information.
*
* Depending on the span implementation, this may return false if the span is not being sampled.
*/
isRecording(): boolean;
/**
* Adds an event to the span.
*/
addEvent?(name: string, options?: AddEventOptions): void;
}
/** An immutable context bag of tracing values for the current operation. */
export interface TracingContext {
/**
* Sets a given object on a context.
* @param key - The key of the given context value.
* @param value - The value to set on the context.
*
* @returns - A new context with the given value set.
*/
setValue(key: symbol, value: unknown): TracingContext;
/**
* Gets an object from the context if it exists.
* @param key - The key of the given context value.
*
* @returns - The value of the given context value if it exists, otherwise `undefined`.
*/
getValue(key: symbol): unknown;
/**
* Deletes an object from the context if it exists.
* @param key - The key of the given context value to delete.
*/
deleteValue(key: symbol): TracingContext;
}
/**
* Tracing options to set on an operation.
*/
export interface OperationTracingOptions {
/** The context to use for created Tracing Spans. */
tracingContext?: TracingContext;
}
/**
* A utility type for when we know a TracingContext has been set
* as part of an operation's options.
*/
export type OptionsWithTracingContext<Options extends {
tracingOptions?: OperationTracingOptions;
}> = Options & {
tracingOptions: {
tracingContext: TracingContext;
};
};
//# sourceMappingURL=interfaces.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../src/interfaces.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,CAAC,SAAS;IAAE,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC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G;IACH,eAAe,CAAC,SAAS,EAAE,KAAK,GAAG,MAAM,GAAG,IAAI,CAAC;IAEjD;;;;OAIG;IACH,WAAW,IAAI,OAAO,CAAC;IAEvB;;OAEG;IACH,QAAQ,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,IAAI,CAAC;CAC1D;AAED,4EAA4E;AAC5E,MAAM,WAAW,cAAc;IAC7B;;;;;;OAMG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,cAAc,CAAC;IACtD;;;;;OAKG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;IAC/B;;;OAGG;IACH,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,CAAC;CAC1C;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,oDAAoD;IACpD,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC;AAED;;;GAGG;AACH,MAAM,MAAM,yBAAyB,CACnC,OAAO,SAAS;IAAE,cAAc,CAAC,EAAE,uBAAuB,CAAA;CAAE,IAC1D,OAAO,GAAG;IACZ,cAAc,EAAE;QACd,cAAc,EAAE,cAAc,CAAC;KAChC,CAAC;CACH,CAAC"}

View File

@@ -0,0 +1,4 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
export {};
//# sourceMappingURL=interfaces.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,3 @@
{
"type": "module"
}

View File

@@ -0,0 +1,8 @@
import { Instrumenter } from "./interfaces.js";
/**
* Defines the shared state between CJS and ESM by re-exporting the CJS state.
*/
export declare const state: {
instrumenterImplementation: Instrumenter | undefined;
};
//# sourceMappingURL=state.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/state.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAK/C;;GAEG;AACH,eAAO,MAAM,KAAK,EAAe;IAC/B,0BAA0B,EAAE,YAAY,GAAG,SAAS,CAAC;CACtD,CAAC"}

View File

@@ -0,0 +1,10 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// @ts-expect-error The recommended approach to sharing module state between ESM and CJS.
// See https://github.com/isaacs/tshy/blob/main/README.md#module-local-state for additional information.
import { state as cjsState } from "../commonjs/state.js";
/**
* Defines the shared state between CJS and ESM by re-exporting the CJS state.
*/
export const state = cjsState;
//# sourceMappingURL=state.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/state.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,yFAAyF;AACzF,wGAAwG;AACxG,OAAO,EAAE,KAAK,IAAI,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEzD;;GAEG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,QAEpB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { Instrumenter } from \"./interfaces.js\";\n// @ts-expect-error The recommended approach to sharing module state between ESM and CJS.\n// See https://github.com/isaacs/tshy/blob/main/README.md#module-local-state for additional information.\nimport { state as cjsState } from \"../commonjs/state.js\";\n\n/**\n * Defines the shared state between CJS and ESM by re-exporting the CJS state.\n */\nexport const state = cjsState as {\n instrumenterImplementation: Instrumenter | undefined;\n};\n"]}

View File

@@ -0,0 +1,9 @@
import { TracingClient, TracingClientOptions } from "./interfaces.js";
/**
* Creates a new tracing client.
*
* @param options - Options used to configure the tracing client.
* @returns - An instance of {@link TracingClient}.
*/
export declare function createTracingClient(options: TracingClientOptions): TracingClient;
//# sourceMappingURL=tracingClient.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"tracingClient.d.ts","sourceRoot":"","sources":["../../src/tracingClient.ts"],"names":[],"mappings":"AAGA,OAAO,EAIL,aAAa,EACb,oBAAoB,EAIrB,MAAM,iBAAiB,CAAC;AAIzB;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,GAAG,aAAa,CAkGhF"}

View File

@@ -0,0 +1,74 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { getInstrumenter } from "./instrumenter.js";
import { knownContextKeys } from "./tracingContext.js";
/**
* Creates a new tracing client.
*
* @param options - Options used to configure the tracing client.
* @returns - An instance of {@link TracingClient}.
*/
export function createTracingClient(options) {
const { namespace, packageName, packageVersion } = options;
function startSpan(name, operationOptions, spanOptions) {
var _a;
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 }));
let tracingContext = startSpanResult.tracingContext;
const span = startSpanResult.span;
if (!tracingContext.getValue(knownContextKeys.namespace)) {
tracingContext = tracingContext.setValue(knownContextKeys.namespace, namespace);
}
span.setAttribute("az.namespace", tracingContext.getValue(knownContextKeys.namespace));
const updatedOptions = Object.assign({}, operationOptions, {
tracingOptions: Object.assign(Object.assign({}, operationOptions === null || operationOptions === void 0 ? void 0 : operationOptions.tracingOptions), { tracingContext }),
});
return {
span,
updatedOptions,
};
}
async function withSpan(name, operationOptions, callback, spanOptions) {
const { span, updatedOptions } = startSpan(name, operationOptions, spanOptions);
try {
const result = await withContext(updatedOptions.tracingOptions.tracingContext, () => Promise.resolve(callback(updatedOptions, span)));
span.setStatus({ status: "success" });
return result;
}
catch (err) {
span.setStatus({ status: "error", error: err });
throw err;
}
finally {
span.end();
}
}
function withContext(context, callback, ...callbackArgs) {
return getInstrumenter().withContext(context, callback, ...callbackArgs);
}
/**
* Parses a traceparent header value into a span identifier.
*
* @param traceparentHeader - The traceparent header to parse.
* @returns An implementation-specific identifier for the span.
*/
function parseTraceparentHeader(traceparentHeader) {
return getInstrumenter().parseTraceparentHeader(traceparentHeader);
}
/**
* Creates a set of request headers to propagate tracing information to a backend.
*
* @param tracingContext - The context containing the span to serialize.
* @returns The set of headers to add to a request.
*/
function createRequestHeaders(tracingContext) {
return getInstrumenter().createRequestHeaders(tracingContext);
}
return {
startSpan,
withSpan,
withContext,
parseTraceparentHeader,
createRequestHeaders,
};
}
//# sourceMappingURL=tracingClient.js.map

File diff suppressed because one or more lines are too long

Some files were not shown because too many files have changed in this diff Show More