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

ExtendedDoubleHistogramBuilder class cast exception #11928

Closed
ArtyomGabeev opened this issue Jul 31, 2024 · 0 comments · Fixed by #11934
Closed

ExtendedDoubleHistogramBuilder class cast exception #11928

ArtyomGabeev opened this issue Jul 31, 2024 · 0 comments · Fixed by #11934
Labels
bug Something isn't working needs triage New issue that requires triage

Comments

@ArtyomGabeev
Copy link
Contributor

Describe the bug

I want to configure custom SpanNameExtract for java HttpClient using opentelemetry-java-http-client instrumentation library.
However opentelemtetry sdk configured via javaagent.
Here is an example:

JavaHttpClientTelemetry.builder(openTelemetry)
      .setSpanNameExtractor(_ => JavaHttpClientSpanNameExtractor)
      .build()
      .newHttpClient(httpClientBuilder.build())

where openTelemetry obtained via: GlobalOpenTelemetry.get()

During startup I get class cast exception:

java.lang.ClassCastException: class io.opentelemetry.javaagent.shaded.io.opentelemetry.api.metrics.DefaultMeter$NoopDoubleHistogramBuilder cannot be cast to class io.opentelemetry.javaagent.shaded.io.opentelemetry.api.incubator.metrics.ExtendedDoubleHistogramBuilder (io.opentelemetry.javaagent.shaded.io.opentelemetry.api.metrics.DefaultMeter$NoopDoubleHistogramBuilder and io.opentelemetry.javaagent.shaded.io.opentelemetry.api.incubator.metrics.ExtendedDoubleHistogramBuilder are in unnamed module of loader 'bootstrap')
	at io.opentelemetry.javaagent.instrumentation.opentelemetryapi.v1_37.incubator.metrics.ApplicationDoubleHistogramBuilder137.setAttributesAdvice(ApplicationDoubleHistogramBuilder137.java:40)
	at io.opentelemetry.instrumentation.api.semconv.http.HttpMetricsAdvice.applyClientDurationAdvice(HttpMetricsAdvice.java:31)
	at io.opentelemetry.instrumentation.api.semconv.http.HttpClientMetrics.<init>(HttpClientMetrics.java:59)
	at io.opentelemetry.instrumentation.api.internal.OperationMetricsUtil.lambda$create$1(OperationMetricsUtil.java:68)
	at io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder.buildOperationListeners(InstrumenterBuilder.java:320)
	at io.opentelemetry.instrumentation.api.instrumenter.Instrumenter.<init>(Instrumenter.java:90)
	at io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder.buildInstrumenter(InstrumenterBuilder.java:284)
	at io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder.buildInstrumenter(InstrumenterBuilder.java:276)
	at io.opentelemetry.instrumentation.httpclient.internal.JavaHttpClientInstrumenterFactory.createInstrumenter(JavaHttpClientInstrumenterFactory.java:70)
	at io.opentelemetry.instrumentation.httpclient.JavaHttpClientTelemetryBuilder.build(JavaHttpClientTelemetryBuilder.java:124)

I'm passing OTEL_METRICS_EXPORTER = none as env variable, since I'm interested only in traces

Note:
If I add OTEL_METRICS_EXPORTER=logging, everything works as expected

Steps to reproduce

  1. Set OTEL_METRICS_EXPORTER=none
  2. Instrument application via javaagent
  3. Try to create JavaHttpClientTelemetry by providing GlobalOpenTelemetry.get()

Expected behavior

If metrics exporter disable, instrumentation should not fail.

Actual behavior

ClassCastException on initialization.

Javaagent or library instrumentation version

2.5.0

Environment

opentelemetry-api: 1.40.0
opentelemetry-java-http-client: 2.6.0-aplha
javaagent: 2.5.0

Additional context

I notice that in other place we have an instance of checks, like:
https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/semconv/http/HttpMetricsAdvice.java#L27

However it may be missed in:
https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation/opentelemetry-api/opentelemetry-api-1.37/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/opentelemetryapi/v1_37/incubator/metrics/ApplicationDoubleHistogramBuilder137.java#L40

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage New issue that requires triage
Projects
None yet
1 participant