Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const azureCoreTracingPatchFunction: PatchFunction = (coreTracing: typeof coreTracingTypes) => {
try {
const BasicTracer = require("@opentelemetry/tracing").BasicTracer;
const tracerConfig = channel.spanContextPropagator
? { scopeManager: channel.spanContextPropagator }
: undefined;
const tracer = new BasicTracer(tracerConfig) as coreTracingTypes.Tracer & { addSpanProcessor: Function };
// Patch startSpan instead of using spanProcessor.onStart because parentSpan must be
// set while the span is constructed
const startSpanOriginal = tracer.startSpan;
tracer.startSpan = function(name: string, options?: coreTracingTypes.SpanOptions) {
// if no parent span was provided, apply the current context
if (!options || !options.parent) {
const parentOperation = tracer.getCurrentSpan();
if (parentOperation && parentOperation.operation && parentOperation.operation.traceparent) {
options = {
...options,
parent: {
traceId: parentOperation.operation.traceparent.traceId,
spanId: parentOperation.operation.traceparent.spanId,
const azureCoreTracingPatchFunction: PatchFunction = (coreTracing: typeof coreTracingTypes) => {
try {
const BasicTracer = require("@opentelemetry/tracing").BasicTracer;
const tracerConfig = channel.spanContextPropagator
? { scopeManager: channel.spanContextPropagator }
: undefined;
const tracer = new BasicTracer(tracerConfig) as coreTracingTypes.Tracer & { addSpanProcessor: Function };
// Patch startSpan instead of using spanProcessor.onStart because parentSpan must be
// set while the span is constructed
const startSpanOriginal = tracer.startSpan;
tracer.startSpan = function(name: string, options?: coreTracingTypes.SpanOptions) {
// if no parent span was provided, apply the current context
if (!options || !options.parent) {
const parentOperation = tracer.getCurrentSpan();
if (parentOperation && parentOperation.operation && parentOperation.operation.traceparent) {
options = {
...options,
parent: {
traceId: parentOperation.operation.traceparent.traceId,
spanId: parentOperation.operation.traceparent.spanId,
},