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

Unable to create synchronous gauge using instrument API #6378

Closed
tongshushan opened this issue Apr 11, 2024 · 4 comments
Closed

Unable to create synchronous gauge using instrument API #6378

tongshushan opened this issue Apr 11, 2024 · 4 comments
Labels
Bug Something isn't working

Comments

@tongshushan
Copy link

Describe the bug
Hello,
refer to: #5506 (comment) ,I want to create synchronous gauge using instrument API, but get error:
java.lang.ClassCastException: io.opentelemetry.sdk.metrics.SdkDoubleGauge$SdkDoubleGaugeBuilder cannot be cast to io.opentelemetry.extension.incubator.metrics.ExtendedDoubleGaugeBuilder

Steps to reproduce

code:

import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.metrics.Meter;
import io.opentelemetry.extension.incubator.metrics.DoubleGauge;
import io.opentelemetry.extension.incubator.metrics.ExtendedDoubleGaugeBuilder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;


@Slf4j
@RestController
public class OtlpTestController {
    @Autowired
    OpenTelemetry openTelemetry;

    @GetMapping("/testSendSynchronizedGauge")
    public String testSendSynchronizedGauge() {
        Meter meter = openTelemetry.meterBuilder("instrumentation-library-name")
                .setInstrumentationVersion("1.0.0")
                .build();
        DoubleGauge gauge = ((ExtendedDoubleGaugeBuilder) meter.gaugeBuilder("my-gauge")).build();
        gauge.set(1.0);
        return "ok";
    }
}

pom.xml:

     <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.12.RELEASE</version>
        <relativePath/> 
    </parent>

 <dependencyManagement>
     <dependencies>
        <dependency>
                <groupId>io.opentelemetry</groupId>
                <artifactId>opentelemetry-bom</artifactId>
                <version>1.37.0</version>
                <type>pom</type>
                <scope>import</scope>
          </dependency>
       </dependencies>
   </dependencyManagement>

    <dependencies>
     <dependency>
            <groupId>io.opentelemetry</groupId>
            <artifactId>opentelemetry-api</artifactId>
        </dependency>
        <dependency>
            <groupId>io.opentelemetry</groupId>
            <artifactId>opentelemetry-sdk</artifactId>
        </dependency>
        <dependency>
            <groupId>io.opentelemetry</groupId>
            <artifactId>opentelemetry-sdk-metrics</artifactId>
        </dependency>
        <dependency>
            <groupId>io.opentelemetry</groupId>
            <artifactId>opentelemetry-exporter-logging</artifactId>
        </dependency>
        <dependency>
            <!-- Not managed by opentelemetry-bom -->
            <groupId>io.opentelemetry.semconv</groupId>
            <artifactId>opentelemetry-semconv</artifactId>
            <version>1.23.1-alpha</version>
        </dependency>
        <dependency>
            <groupId>io.opentelemetry</groupId>
            <artifactId>opentelemetry-sdk-extension-autoconfigure</artifactId>
        </dependency>
        <dependency>
            <groupId>io.opentelemetry</groupId>
            <artifactId>opentelemetry-sdk-extension-autoconfigure-spi</artifactId>
        </dependency>
        <dependency>
            <groupId>io.opentelemetry</groupId>
            <artifactId>opentelemetry-exporter-otlp</artifactId>
        </dependency>
        <dependency>
            <groupId>io.opentelemetry</groupId>
            <artifactId>opentelemetry-extension-incubator</artifactId>
            <version>1.36.0-alpha</version>
        </dependency>
        <dependency>
            <groupId>io.opentelemetry.instrumentation</groupId>
            <artifactId>opentelemetry-instrumentation-api-semconv</artifactId>
            <version>1.29.0-alpha</version>
        </dependency>
        <dependency>
            <groupId>io.opentelemetry.instrumentation</groupId>
            <artifactId>opentelemetry-logback-appender-1.0</artifactId>
            <version>1.29.0-alpha</version>
        </dependency>
      </dependencies>

What did you expect to see?
Call the test method: testSendSynchronizedGauge() should send synchronous gauge.

What did you see instead?
java.lang.ClassCastException: io.opentelemetry.sdk.metrics.SdkDoubleGauge$SdkDoubleGaugeBuilder cannot be cast to io.opentelemetry.extension.incubator.metrics.ExtendedDoubleGaugeBuilder

Environment
OS: "Win11"
java version: "1.8.0_121"
springboot: 2.3.12.RELEASE

@tongshushan tongshushan added the Bug Something isn't working label Apr 11, 2024
@jack-berg
Copy link
Member

Can you check the version of all your dependencies? I noticed you using spring, which we've seen is quite stubborn about the versions of opentelemetry artifacts it brings in. I suspect that you successfully upgraded some artifact versions, but not all, and opentelemetry-java artifacts all need to be kept in sync at the same version.

See this #6018 (comment) for a few different ways people have found to override the version from spring dependency management.

@tongshushan
Copy link
Author

tongshushan commented Apr 12, 2024

Hi @jack-berg :

<dependencyManagement>
    <dependencies>
        <dependency>
                <groupId>io.opentelemetry</groupId>
                <artifactId>opentelemetry-bom</artifactId>
                <version>1.37.0</version>
                <type>pom</type>
                <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>
....
<dependencies>
    <dependency>
            <groupId>io.opentelemetry</groupId>
            <artifactId>opentelemetry-extension-incubator</artifactId>
            <version>1.36.0-alpha</version>
    </dependency>
</dependencies>

The latest opentelemetry-extension-incubator lib on Maven Repository is: 1.36.0-alpha
I degrade the opentelemetry-bom from 1.37.0 to 1.36.0, then it's working.

Thank for help.

@trask
Copy link
Member

trask commented Apr 12, 2024

hi @tongshushan, opentelemetry-extension-incubator was renamed to opentelemetry-api-incubator in 1.37.0, I think making that change should get it working in 1.37.0 for you

@tongshushan
Copy link
Author

Hi @trask , your suggestion is also working, thanks.

opentelemetry-api-incubator on maven repositry is 1.37.0-alpha https://mvnrepository.com/artifact/io.opentelemetry/opentelemetry-api-incubator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants