open-telemetry / opentelemetry-js

OpenTelemetry JavaScript Client
https://opentelemetry.io
Apache License 2.0
2.71k stars 785 forks source link

Can I use auto-instrumentation & manual instrumentation at the same time? #4951

Open floatingstarlight opened 1 month ago

floatingstarlight commented 1 month ago

Hi, I'm now developing an full-stack application, and I'm trying to use both auto-instrumentation & manual instrumentation of traces at the same time through openTelemtry, and export my trace information to honeyComb Dashboard.

But it seems that I cannot make both exporting to honeycomb dashboard, but I can export both to ConsoleExporter.

My questions: 1.What might be problems in my case? 2.I've seen we can also create traceProvider to implement custom implementation, what would be the difference between Creating traceProvider vs. sdk-start method?

Here is my implementation:

1.Auto-instrumentation:

new opentelemetry.NodeSDK({
                traceExporter: new OTLPTraceExporter({
                url: 
                headers: {},
                instrumentations: [getNodeAutoInstrumentations()],
            });

3.Custom-instrumentation:

const tracer = opentelemetry.trace.getTracer("backstage-trace");

function(): {
    tracer.startActiveSpan('xxx', (span: Span) => {
    span.end();
}

And when I use consoleExporter, both data can be recorded. But when it comes to honeyComb dashboard, only the auto-Instrumentation data are recorded.

Thanks so much!

pichlermarc commented 1 month ago

I've seen we can also create traceProvider to implement custom implementation, what would be the difference between Creating traceProvider vs. sdk-start method?

Creating an registering a TracerProvider is needed if you need more control over the SDK setup. If there's anything not available through @opentelemetry/sdk-node then registereing a TracerProvider is the preferred way of setting up the SDK. Another reason to manually set up a TracerProvider is when you don't want to use an experimental package that includes possible breaking changes in semver-minor versions (@opentelemetry/sdk-node is still 0.x so minor version bumps may include breaking changes according to semver).

And when I use consoleExporter, both data can be recorded. But when it comes to honeyComb dashboard, only the auto-Instrumentation data are recorded.

If the data shows up the ConsoleExporter and everything is set up correctly, it will also be exported by the OTLP Exporter. I'm not sure if the issue for you is on the OTel side or the way it is displayed in Honeycomb. Pinging @JamieDanielson as she's more familiar with that particular product :slightly_smiling_face:

JamieDanielson commented 3 weeks ago

@floatingstarlight If both are exported to the Console but not to Honeycomb, that sounds like something is off with the exporter configuration. You can set OTEL_LOG_LEVEL=debug to see if there are any hints there. Can you share how you are exporting to the Console? Is it a Console Exporter, or DiagLogger, or something else?