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

add OpenTelemetryTracingModule #11477

Merged
merged 3 commits into from
Aug 30, 2024
Merged

Conversation

YifeiZhuang
Copy link
Contributor

@YifeiZhuang YifeiZhuang commented Aug 15, 2024

What is missing.

  1. Server side Context propagation, i.e. in StreamTracer.filterContext(), OpenTelemetry Context does not automatically propagate to another thread. This needs a separate PR to override grpcContextStorage.
  2. inboundMessageRead in deframer will supply optionalWireSize == optionalUncompressedSize in compression situation.

#11409


private String generateErrorStatusDescription(io.grpc.Status status) {
if (status.getDescription() != null) {
return status.getCode() + ". " + status.getDescription();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: We generally use : between the code and description.

TIL Java now lets you do string concatenation with a non-string left operand.

public final GrpcServerRule grpcServerRule = new GrpcServerRule().directExecutor();
private Tracer tracerRule;
@Mock
private Tracer mockTracer;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, I would have really preferred not using mocks all though here, as we don't know if we're using OTel properly. But since these are interfaces, at least we aren't doing horrible things to other people's objects, but we won't get default methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I mostly use real otel from OpenTelemetryRule.
But they hardcoded w3c propagator in the rule.
https://github.com/open-telemetry/opentelemetry-java/blob/97b3fa42f10d43a4f27ecdf2d809bca95fed4de3/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/junit4/OpenTelemetryRule.java#L87
So whenever I wanted to test our grpcTraceBinContextPropagator I used mock.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should contribute to the OpenTelemetryRule package to use custom propagator.

private static final Logger logger = Logger.getLogger(OpenTelemetryTracingModule.class.getName());

@VisibleForTesting
static final String OTEL_TRACING_SCOPE_NAME = "grpc-opentelemetry-tracing";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to include the language in the scope name to different scope across languages?
For instance, we used grpc-java for Metrics.

Comment on lines +302 to +304
Span clientSpan = otelTracer.spanBuilder(
generateTraceSpanName(false, method.getFullMethodName()))
.startSpan();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can we specify the parent span for this if one exists?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great question! Opentelemetry sdk by default pulls in the current span on the io.opentelemetry.context as it's parent span.
https://github.com/open-telemetry/opentelemetry-java/blob/main/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SdkSpanBuilder.java#L185-L186
Users will just makeCurrent() of the parent span using opentelemetry context API.
Interceptor are run in channel thread.

@YifeiZhuang
Copy link
Contributor Author

@ejona86 @DNVindhya I'm merging this. Feel free to comment and I'll address in future PRs.

@YifeiZhuang YifeiZhuang merged commit 421e237 into grpc:master Aug 30, 2024
15 checks passed
@YifeiZhuang YifeiZhuang deleted the otel-tracing-module branch August 30, 2024 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants