Permalink
Cannot retrieve contributors at this time
63 lines (63 sloc)
2.78 KB
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
codeql-action/node_modules/@azure/core-tracing/dist-esm/src/createSpan.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) Microsoft Corporation. | |
// Licensed under the MIT license. | |
import { SpanKind, setSpan, context as otContext, getTracer } from "./interfaces"; | |
import { trace, INVALID_SPAN_CONTEXT } from "@opentelemetry/api"; | |
export function isTracingDisabled() { | |
var _a; | |
if (typeof process === "undefined") { | |
// not supported in browser for now without polyfills | |
return false; | |
} | |
const azureTracingDisabledValue = (_a = process.env.AZURE_TRACING_DISABLED) === null || _a === void 0 ? void 0 : _a.toLowerCase(); | |
if (azureTracingDisabledValue === "false" || azureTracingDisabledValue === "0") { | |
return false; | |
} | |
return Boolean(azureTracingDisabledValue); | |
} | |
/** | |
* Creates a function that can be used to create spans using the global tracer. | |
* | |
* Usage: | |
* | |
* ```typescript | |
* // once | |
* const createSpan = createSpanFunction({ packagePrefix: "Azure.Data.AppConfiguration", namespace: "Microsoft.AppConfiguration" }); | |
* | |
* // in each operation | |
* const span = createSpan("deleteConfigurationSetting", operationOptions); | |
* // code... | |
* span.end(); | |
* ``` | |
* | |
* @hidden | |
* @param args - allows configuration of the prefix for each span as well as the az.namespace field. | |
*/ | |
export function createSpanFunction(args) { | |
return function (operationName, operationOptions) { | |
const tracer = getTracer(); | |
const tracingOptions = (operationOptions === null || operationOptions === void 0 ? void 0 : operationOptions.tracingOptions) || {}; | |
const spanOptions = Object.assign({ kind: SpanKind.INTERNAL }, tracingOptions.spanOptions); | |
const spanName = args.packagePrefix ? `${args.packagePrefix}.${operationName}` : operationName; | |
let span; | |
if (isTracingDisabled()) { | |
span = trace.wrapSpanContext(INVALID_SPAN_CONTEXT); | |
} | |
else { | |
span = tracer.startSpan(spanName, spanOptions, tracingOptions.tracingContext); | |
} | |
if (args.namespace) { | |
span.setAttribute("az.namespace", args.namespace); | |
} | |
let newSpanOptions = tracingOptions.spanOptions || {}; | |
if (span.isRecording() && args.namespace) { | |
newSpanOptions = Object.assign(Object.assign({}, tracingOptions.spanOptions), { attributes: Object.assign(Object.assign({}, spanOptions.attributes), { "az.namespace": args.namespace }) }); | |
} | |
const newTracingOptions = Object.assign(Object.assign({}, tracingOptions), { spanOptions: newSpanOptions, tracingContext: setSpan(tracingOptions.tracingContext || otContext.active(), span) }); | |
const newOperationOptions = Object.assign(Object.assign({}, operationOptions), { tracingOptions: newTracingOptions }); | |
return { | |
span, | |
updatedOptions: newOperationOptions | |
}; | |
}; | |
} | |
//# sourceMappingURL=createSpan.js.map |