How to use the diagnostic-channel.channel.spanContextPropagator function in diagnostic-channel

To help you get started, we’ve selected a few diagnostic-channel examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / node-diagnostic-channel / src / diagnostic-channel-publishers / src / azure-coretracing.pub.ts View on Github external
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,
github microsoft / node-diagnostic-channel / src / diagnostic-channel-publishers / src / azure-coretracing.pub.ts View on Github external
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,
                        },

diagnostic-channel

Provides a context-saving pub/sub channel to connect diagnostic event publishers and subscribers

MIT
Latest version published 1 year ago

Package Health Score

74 / 100
Full package analysis

Similar packages