mirror of
https://github.com/tvytlx/ai-agent-deep-dive.git
synced 2026-04-05 00:24:50 +08:00
Add extracted source directory and README navigation
This commit is contained in:
14
extracted-source/node_modules/@azure/core-tracing/dist/commonjs/state.js
generated
vendored
Normal file
14
extracted-source/node_modules/@azure/core-tracing/dist/commonjs/state.js
generated
vendored
Normal 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
|
||||
5
extracted-source/node_modules/@azure/core-tracing/dist/esm/index.js
generated
vendored
Normal file
5
extracted-source/node_modules/@azure/core-tracing/dist/esm/index.js
generated
vendored
Normal 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
|
||||
63
extracted-source/node_modules/@azure/core-tracing/dist/esm/instrumenter.js
generated
vendored
Normal file
63
extracted-source/node_modules/@azure/core-tracing/dist/esm/instrumenter.js
generated
vendored
Normal 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
|
||||
10
extracted-source/node_modules/@azure/core-tracing/dist/esm/state.js
generated
vendored
Normal file
10
extracted-source/node_modules/@azure/core-tracing/dist/esm/state.js
generated
vendored
Normal 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
|
||||
74
extracted-source/node_modules/@azure/core-tracing/dist/esm/tracingClient.js
generated
vendored
Normal file
74
extracted-source/node_modules/@azure/core-tracing/dist/esm/tracingClient.js
generated
vendored
Normal 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
|
||||
47
extracted-source/node_modules/@azure/core-tracing/dist/esm/tracingContext.js
generated
vendored
Normal file
47
extracted-source/node_modules/@azure/core-tracing/dist/esm/tracingContext.js
generated
vendored
Normal 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
|
||||
Reference in New Issue
Block a user