Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Propagator not working #240

Closed
facucus opened this issue Aug 3, 2023 · 2 comments
Closed

Custom Propagator not working #240

facucus opened this issue Aug 3, 2023 · 2 comments
Labels
bug Report a bug

Comments

@facucus
Copy link

facucus commented Aug 3, 2023

Description

We want to create a new propagator to fetch traceid/spanid from a URL, I create a new propagator and assign it to the instrumentation but I never see my code being executed.

Steps to reproduce

class UrlPropagator  {
    fields() {
        return ['traceid', 'spanid'];
    }

    inject(context, carrier: unknown, setter: TextMapSetter): void {
    }

    extract(context, carrier, getter) {
        const traceId = getter.get(carrier, 'traceId');
        const spanId = getter.get(carrier, 'spanId');
        console.log("extract: ", traceId, spanId)
        if (!traceId || !spanId) {
            return context;
        }
        const spanContext = {
            traceId,
            spanId,
            traceFlags: TraceFlags.SAMPLED,
        };
        console.log("spanContext: ", spanContext)
        return trace.setSpanContext(context, spanContext);
    }
}
...initializeFaro
new TracingInstrumentation({
      propagator: new UrlPropagator()
}),

Expected behavior

We expect the propagator be executed and at least see the console.log

Actual behavior

The propagator it's never executed

@facucus facucus added the bug Report a bug label Aug 3, 2023
@cedricziel
Copy link
Contributor

I think the Web SDK is behaving correctly in this case.

The intention of a propagator is to extract information from an incoming request and to inject information into an outgoing request. OpenTelemetry tracing propagates context forward, not backwards.

Ref: https://opentelemetry.io/docs/specs/otel/context/api-propagators/#extract

Extracts the value from an incoming request. For example, from the headers of an HTTP request.

In case the intention is to capture every interaction in a single trace, the OpenTelemetry docs list an example how to map a server-started trace and use it as root-span for your browser level tracing needs. https://opentelemetry.io/docs/instrumentation/js/getting-started/browser/#example-application

We are exploring ways to connect client side events stronger with server side context by using a lose coupling. We are tracking #216 which captures the initial ideation around using server-timing http headers and enhancements to our new fetch instrumentation to create the context necessary.

@codecapitano
Copy link
Collaborator

@facucus @cedricziel Can we close this issue or is anything left to clarify?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Report a bug
Projects
None yet
Development

No branches or pull requests

3 participants