Giter VIP home page Giter VIP logo

Comments (2)

alexandrebrg avatar alexandrebrg commented on June 11, 2024

For now, I ended up with a POC through a nest interceptor.

import {
    CallHandler,
    ExecutionContext,
    Injectable,
    NestInterceptor
} from "@nestjs/common";
import { Observable } from "rxjs";
import { TraceService } from "nestjs-otel";

@Injectable()
export class TracingInjectionInterceptor implements NestInterceptor {
    private static EXPECTED_B3_ARRAY_LENGTH = 3;
    constructor(private readonly traceService: TraceService) {}

    intercept(
        context: ExecutionContext,
        next: CallHandler
    ): Observable<unknown> {
        const b3Context = this.extractB3Headers(context);

        if (b3Context.length < TracingInjectionInterceptor.EXPECTED_B3_ARRAY_LENGTH) {
            return next.handle();
        }

        this.injectB3ContextToTrace(b3Context);
        return next.handle();
    }

    extractB3Headers(context: ExecutionContext): string[] {
        const b3: string = context.switchToHttp().getRequest().headers["b3"];
        if (!b3) return [];

        return b3.split("-");
    }

    injectB3ContextToTrace(spanContext: string[]) {
        const traceCtx = this.traceService.getSpan().spanContext();
        traceCtx.traceId = spanContext[0];
        traceCtx.spanId = spanContext[1];
        traceCtx.isRemote = true;
        traceCtx.traceFlags = Number(spanContext[2]);
    }
}

from nestjs-otel.

pragmaticivan avatar pragmaticivan commented on June 11, 2024

Hi @alexandrebrg what you did will likely work on NestJS side but There might be a way that you can plug your own propagator that reads from B2 in the NodeJS SDK. Unlikely to be solved by this lib though, sorry.

from nestjs-otel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.