Open DNVindhya opened 1 year 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.
@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();
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?
Notes from API review on 2024-05-02:
channelBuilder.addPlugin(openTelemetryPlugin)
, but we preferred the existing clear-but-less-pretty approach. It can always be done in the future