async-graphql icon indicating copy to clipboard operation
async-graphql copied to clipboard

Tracing & Open Telemetry Examples

Open kennetpostigo opened this issue 4 years ago • 6 comments

Are there any example servers that implement Tracing & Open Telemetry? I couldn't find any in the examples repo, and wondering if there are any OSS example usage of this?

kennetpostigo avatar Mar 21 '22 14:03 kennetpostigo

There is no example, basically you just need to initialize the tracer and pass it to the OpenTelemetry extension, it will work.

sunli829 avatar Mar 22 '22 03:03 sunli829

Do we need to do something special to link the spans with the traceparent HTTP header?

I'm using axum.

I wonder if extensions/opentelemetry.rs would need to do something like:

https://github.com/tokio-rs/tracing/blob/1e09e50e8d15580b5929adbade9c782a6833e4a0/examples/examples/opentelemetry-remote-context.rs#L32-L40

Is it possible to access the HTTP request headers in extensions/opentelemetry.rs?

EDIT: maybe it should try to work with the integrations. like with axum_tracing_opentelemetry.

EDIT: it's also confusing that when using both tracing_subscriber and the opentelemetry extension, the spans are sent twice.

bbigras avatar Jul 20 '22 23:07 bbigras

For the traceparent HTTP header you just need to create you own Propagator with opentelemetry, with this Propagator you need to implement the TextMapPropagator trait to play with the Extractor and Injector. It's not something linked to async-graphql. Just using the tracing extension is enough to have the span

Miaxos avatar Jul 21 '22 21:07 Miaxos

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Aug 29 '22 02:08 github-actions[bot]

I've been recently messing around with opentelemetry, still a WIP as i've moved onto other things while I do more research but I did manage to get the output sent to my terminal:

let tracer = stdout::new_pipeline().install_simple();
let opentelemetry_extension = OpenTelemetry::new(tracer);

// ...graphql schema
.extension(opentelemetry_extension)

In Cargo.toml

async-graphql = { version = "4.0.12", features = ["opentelemetry"] }
opentelemetry = "0.17.0"

The issue I opened to learn more about it https://github.com/async-graphql/async-graphql/issues/1031

There are also some examples of what @Miaxos suggested out in the wild if you dig deep enough, I can't remember exactly where I found them though sorry!

I think the documentation within async-graphql for this topic could be improved though - @kennetpostigo I'd be happy to work with you to do that and maybe add an example too if it makes sense.

onx2 avatar Sep 03 '22 11:09 onx2

I added a basic stdout pipeline example https://github.com/async-graphql/examples/pull/59 and will be adding a jaeger one soon

onx2 avatar Sep 17 '22 16:09 onx2