grpc / grpc-java

The Java gRPC implementation. HTTP/2 based RPC
https://grpc.io/docs/languages/java/
Apache License 2.0
11.46k stars 3.85k forks source link

OpenTelemetryModule is experimental #10591

Open DNVindhya opened 1 year ago

ejona86 commented 6 months ago

Notes from API review on 2024-05-02:

ejona86 commented 6 months ago

Reopening for GrpcOpenTelemetry.registerGlobal(), which at least needs documentation updates. But I think there's some details still to work out with how the global works.

surbhigarg92 commented 2 months ago

@ejona86 I am trying to use GrpcOpenTelemetry.registerGlobal() and I am getting error java.lang.IllegalStateException: Configurators are already set . I am using it with Spanner Client library and registering the GrpcOpenTelemetry before instantiating Spanner Client . Please refer the code below.

SdkMeterProvider sdkMeterProvider = SdkMeterProvider.builder()
        .registerMetricReader(
            PeriodicMetricReader.builder(GoogleCloudMetricExporter.createWithDefaultConfiguration())
                .build())
        .build();

    OpenTelemetry openTelemetry = OpenTelemetrySdk.builder()
        .setMeterProvider(sdkMeterProvider)
        .build();

    GrpcOpenTelemetry grpcOpenTelemetry = GrpcOpenTelemetry.newBuilder().enableMetrics(new HashSet<>(
        Arrays.asList("grpc.client.attempt.duration"))).sdk(openTelemetry).build();
    grpcOpenTelemetry.registerGlobal();

    SpannerOptions options = SpannerOptions.newBuilder()
        .setOpenTelemetry(openTelemetry)
        .build();
    Spanner spanner = options.getService();
Kresshy commented 1 month ago

I'm running into this but instead of the Spanner client we have this issue with the logging appender, StackdriverAppender.

Logger is a static field in our codebase and it is getting initialized before everything else. Logging is happening through gRPC and as far as I can tell when it creates the ManagedChannelImplBuilder it calls into the InternalConfiguratorRegistry.configureChannelBuilder(), which obviously will freeze the config when iterating through the existing configurators via ConfiguratorRegistry.getDefaultRegistry().getConfigurators().

I think this is expected but all these problems make it hard to use this library with other Google Cloud Libraries. By the time you get to initialize the OTEL SDK and GrpcOpenTelemetry and you have to call grpcOpenTelemetry.registerGlobal(); potentially when you do this the configurators are already set or frozen.

Is there any other way to initialize grpc opentelemetry and still collect the metrics plus the traces from the grpc service endpoints?

Would it be possible to make the configurators mutable?