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

Context propagation not working with RxJS #2138

Open
2 tasks done
jdespatis opened this issue Apr 22, 2024 · 0 comments
Open
2 tasks done

Context propagation not working with RxJS #2138

jdespatis opened this issue Apr 22, 2024 · 0 comments

Comments

@jdespatis
Copy link

Hello,

I'm testing OpenTelemetry with RxJS, which is used in Angular, NestJS for which instrumentations already exist
I'm also using auto-instrumentations-node

The fact is context doesn't seem to be propagated, maybe I'm missing something?

It works if I inject manually the context

Here is a test script to reproduce:

import { trace, context } from '@opentelemetry/api';
import { of, tap } from 'rxjs';

const tracer = trace.getTracer('example');
const logContext = (message: string) => console.log(message, context.active());
const ob = tracer.startActiveSpan('my-lib', () => {
  const ctx = context.active();

  // Context is the expected one, corresponding to 'my-lib' active span
  logContext('Before observable');

  return of(1).pipe(
    // Context is BASE_CONTEXT, not the expected one
    tap(() => logContext('In pipeline, but without context provided')),

    // Context is the expected one, corresponding to 'my-lib' active span
    tap(() => context.with(ctx, logContext, undefined, 'In pipeline, with context provided'))
  );
});

ob.subscribe();
  • The first tap operator won't benefit from the active context
  • the second one will benefit from it, because context is injected with context.with

Is there a smarter way to achieve this, more automatically?

This issue may affect other languages where Rx is also available RxJava, RxGo, etc..

  • This only affects the JavaScript OpenTelemetry library
  • This may affect other libraries, but I would like to get opinions here first
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant