open-telemetry / opentelemetry.io

The OpenTelemetry website and documentation
https://opentelemetry.io
Creative Commons Attribution 4.0 International
487 stars 1.01k forks source link

Exporters example does not compile: SERVICE_NAME and SERVICE_VERSION are not defined. #4328

Open garydgregory opened 2 months ago

garydgregory commented 2 months ago

This line does not compile:

Resource resource = Resource.getDefault().toBuilder().put(SERVICE_NAME, "dice-server").put(SERVICE_VERSION, "0.1.0").build();

from https://opentelemetry.io/docs/languages/java/exporters/

theletterf commented 2 months ago

@garydgregory What's your runtime and OS?

+CC @open-telemetry/java-instrumentation-maintainers

laurit commented 2 months ago

https://github.com/open-telemetry/opentelemetry.io/blob/807fd51093c8ee6b156010ae0c9a70d06cf4d150/content/en/docs/languages/java/instrumentation.md seems to have a similar sample. That sample uses ResourceAttributes.SERVICE_NAME instead of SERVICE_NAME also the import for ResourceAttributes is different.

garydgregory commented 2 months ago

I am using Java 17 on Windows 10 with Maven:

ver && java -version && mvn -version

Microsoft Windows [Version 10.0.19045.4170]
openjdk version "17.0.8" 2023-07-18
OpenJDK Runtime Environment Temurin-17.0.8+7 (build 17.0.8+7)
OpenJDK 64-Bit Server VM Temurin-17.0.8+7 (build 17.0.8+7, mixed mode, sharing)
Apache Maven 3.9.6 (bc0240f3c744dd6b6ec2920b3cd08dcc295161ae)
Maven home: C:\java\apache-maven-3.9.6
Java version: 17.0.8, vendor: Eclipse Adoptium, runtime: C:\Program Files\Eclipse Adoptium\jdk-17.0.8.7-hotspot
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

My IDE is Eclipse:

Version: 2024-03 (4.31.0)

This includes Buildship (the Gradle thing that does not really work, see https://github.com/eclipse/buildship/issues/1303)

garydgregory commented 2 months ago

Both ResourceAttributes.SERVICE_NAME and ResourceAttributes.SERVICE_VERSION are deprecated, so what's supposed to go in these put calls?

laurit commented 2 months ago

@garydgregory with the latest semconv artifact it is io.opentelemetry.semconv.ServiceAttributes.SERVICE_NAME

garydgregory commented 2 months ago

Hello @laurit My dependency management section uses:

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

Version "1.37.0" looks like the latest: https://search.maven.org/artifact/io.opentelemetry/opentelemetry-bom

My dependency section uses:

    <dependency>
      <groupId>io.opentelemetry.instrumentation</groupId>
      <artifactId>opentelemetry-log4j-appender-2.17</artifactId>
      <version>2.3.0-alpha</version>
    </dependency>
    <dependency>
      <groupId>io.opentelemetry</groupId>
      <artifactId>opentelemetry-exporter-otlp</artifactId>
    </dependency>

mvn dependency:tree says:

[INFO] +- io.opentelemetry.instrumentation:opentelemetry-log4j-appender-2.17:jar:2.3.0-alpha:compile
[INFO] |  +- io.opentelemetry.instrumentation:opentelemetry-instrumentation-api:jar:2.3.0:compile
[INFO] |  |  +- io.opentelemetry:opentelemetry-api-incubator:jar:1.37.0-alpha:runtime
[INFO] |  |  +- io.opentelemetry.semconv:opentelemetry-semconv:jar:1.25.0-alpha:compile
[INFO] |  |  \- io.opentelemetry.semconv:opentelemetry-semconv-incubating:jar:1.25.0-alpha:compile
[INFO] |  +- io.opentelemetry.instrumentation:opentelemetry-instrumentation-api-incubator:jar:2.3.0-alpha:compile
[INFO] |  \- io.opentelemetry:opentelemetry-api:jar:1.37.0:compile
[INFO] |     \- io.opentelemetry:opentelemetry-context:jar:1.37.0:compile
[INFO] \- io.opentelemetry:opentelemetry-exporter-otlp:jar:1.37.0:compile
[INFO]    +- io.opentelemetry:opentelemetry-sdk-trace:jar:1.37.0:compile
[INFO]    |  \- io.opentelemetry:opentelemetry-sdk-common:jar:1.37.0:compile
[INFO]    +- io.opentelemetry:opentelemetry-sdk-metrics:jar:1.37.0:compile
[INFO]    +- io.opentelemetry:opentelemetry-sdk-logs:jar:1.37.0:compile
[INFO]    +- io.opentelemetry:opentelemetry-exporter-otlp-common:jar:1.37.0:runtime
[INFO]    |  \- io.opentelemetry:opentelemetry-exporter-common:jar:1.37.0:runtime
[INFO]    +- io.opentelemetry:opentelemetry-exporter-sender-okhttp:jar:1.37.0:runtime
[INFO]    |  \- com.squareup.okhttp3:okhttp:jar:4.12.0:runtime
[INFO]    |     +- com.squareup.okio:okio:jar:3.6.0:runtime
[INFO]    |     |  \- com.squareup.okio:okio-jvm:jar:3.6.0:runtime
[INFO]    |     |     \- org.jetbrains.kotlin:kotlin-stdlib-common:jar:1.9.10:runtime
[INFO]    |     \- org.jetbrains.kotlin:kotlin-stdlib-jdk8:jar:1.8.21:runtime
[INFO]    |        +- org.jetbrains.kotlin:kotlin-stdlib:jar:1.8.21:runtime
[INFO]    |        \- org.jetbrains.kotlin:kotlin-stdlib-jdk7:jar:1.8.21:runtime
[INFO]    \- io.opentelemetry:opentelemetry-sdk-extension-autoconfigure-spi:jar:1.37.0:runtime
[INFO]       \- io.opentelemetry:opentelemetry-sdk:jar:1.37.0:runtime

The class is in opentelemetry-semconv-1.25.0-alpha.jar which is the latest according to https://search.maven.org/artifact/io.opentelemetry.semconv/opentelemetry-semconv

What am I missing?

TY.

laurit commented 2 months ago

@garydgregory what is the issue that you have?

garydgregory commented 2 months ago

Hello @laurit 1) Like the title of the ticket says "Exporters example does not compile", so that needs fixing. 2) The offered solution uses deprecate code, so what's the supported code supposed to look like?

svrnm commented 1 month ago

@open-telemetry/java-approvers PTAL