open-telemetry / opentelemetry-js

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

Question: Does trace context propagation supposed to be automatic with gRPC client? #1664

Open longility opened 3 years ago

longility commented 3 years ago

Here is a slimmed down configuration that I have.

//tracer.ts
import { GraphQLInstrumentation } from "@opentelemetry/instrumentation-graphql";
import { NodeTracerProvider } from "@opentelemetry/node";

const provider = new NodeTracerProvider();
const graphQLInstrumentation = new GraphQLInstrumentation();

graphQLInstrumentation.setTracerProvider(provider);

graphQLInstrumentation.enable();
provider.register();
//package.json
{ "dependencies": {
    "@grpc/grpc-js": "^1.1.8",
    "@opentelemetry/api": "^0.12.0",
    "@opentelemetry/instrumentation-graphql": "^0.11.0",
    "@opentelemetry/node": "^0.12.0",
    "@opentelemetry/plugin-express": "^0.11.0",
    "@opentelemetry/plugin-grpc-js": "^0.12.0",
    "@opentelemetry/plugin-http": "^0.12.0",
    "@opentelemetry/tracing": "^0.12.0",
    "apollo-server": "^2.19.0"
} }

I'm using apollo as my gateway and making grpc clients to my microservices. I do have other metadata that I'm adding manually, which I don't think should matter.

Expectation I do not have to manually set metadata/headers for the grpc client when making calls. It should be automatic.

Actual I don't see any trace context on my gRPC server when checking request headers. I tested by manually adding the trace context using span.context() to get the data to pass as metadata, and it showed up.

Do I have the right expectation? Is there something I should try that I may have missed? How can I debug further? Thoughts?

dyladan commented 3 years ago

You do have the right expectation. I'm looking into this now.

longility commented 3 years ago

Thank you @dyladan . Let me know if you need more info or need me to try something.

dyladan commented 3 years ago

Are you sure you're using the right grpc plugin? We have plugins for grpc and for grpc-js which are different modules

longility commented 3 years ago

I believe so. You can verify as I have my package dependencies shown in comment above. Here is a more slim version:

//package.json
{ "dependencies": {
    "@grpc/grpc-js": "^1.1.8",
    "@opentelemetry/plugin-grpc-js": "^0.12.0"
} }

and in logs it shows this PluginLoader#load: trying to load @grpc/grpc-js@1.1.8 and doesn't error after that line.

dyladan commented 3 years ago

ok great thanks.