opentelemetry.io icon indicating copy to clipboard operation
opentelemetry.io copied to clipboard

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

Open garydgregory opened this issue 1 year ago • 9 comments

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/

garydgregory avatar Apr 20 '24 01:04 garydgregory

@garydgregory What's your runtime and OS?

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

theletterf avatar Apr 22 '24 07:04 theletterf

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.

laurit avatar Apr 22 '24 08:04 laurit

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 avatar Apr 22 '24 11:04 garydgregory

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

garydgregory avatar Apr 22 '24 11:04 garydgregory

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

laurit avatar Apr 22 '24 12:04 laurit

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.

garydgregory avatar Apr 22 '24 12:04 garydgregory

@garydgregory what is the issue that you have?

laurit avatar Apr 22 '24 13:04 laurit

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?

garydgregory avatar Apr 22 '24 13:04 garydgregory

@open-telemetry/java-approvers PTAL

svrnm avatar May 02 '24 09:05 svrnm

Hi! Following up on this — the Java docs have been refactored since this issue was opened (see #4966), and the exporters section was updated as part of that work as well.

Given that, this issue should now be resolved, so I'll go ahead and close it.

If you're still seeing anything off in the current docs or examples, please feel free to open a new issue!

Thanks 😄

vitorvasc avatar Nov 21 '25 10:11 vitorvasc