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

Rework java manual instrumentation #3144

Merged
merged 26 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
705cbe9
Rework java manual instrumentation
svrnm Aug 2, 2023
09140a6
updates
svrnm Aug 4, 2023
e341f0d
Merge branch 'main' into java-manual-instrumentation
svrnm Aug 8, 2023
2cc0984
finalize first draft
svrnm Aug 8, 2023
2646667
Merge branch 'main' into java-manual-instrumentation
svrnm Aug 8, 2023
6b325e1
fixes
svrnm Aug 8, 2023
bca9d34
markdown issue fixes
svrnm Aug 8, 2023
54b09d4
Updates following feedback
svrnm Aug 9, 2023
6356388
Merge branch 'main' into java-manual-instrumentation
svrnm Aug 9, 2023
0a6dd88
Update content/en/docs/instrumentation/java/manual.md
svrnm Sep 6, 2023
ff9383a
Update content/en/docs/instrumentation/java/manual.md
svrnm Sep 6, 2023
647cb7e
Update content/en/docs/instrumentation/java/exporters.md
svrnm Sep 6, 2023
bf48195
resolving suggestions
svrnm Sep 8, 2023
550e6ed
Merge branch 'main' into java-manual-instrumentation
svrnm Sep 11, 2023
e19548a
Apply suggestions from code review
svrnm Sep 11, 2023
bf2d056
Merge branch 'main' into java-manual-instrumentation
svrnm Sep 11, 2023
ea8a2a9
Update content/en/docs/instrumentation/java/manual.md
svrnm Sep 11, 2023
70d9ac9
Update content/en/docs/instrumentation/java/manual.md
svrnm Sep 11, 2023
62b4cb5
Merge branch 'main' into java-manual-instrumentation
svrnm Sep 13, 2023
0aa265d
Merge branch 'main' into java-manual-instrumentation
svrnm Sep 13, 2023
839ab5e
fixes
svrnm Sep 13, 2023
624bb55
fix typo
svrnm Sep 13, 2023
5de87c7
fix markdown issue
svrnm Sep 13, 2023
8ee2a72
Update content/en/docs/instrumentation/java/manual.md
svrnm Sep 13, 2023
307b447
Merge branch 'main' into java-manual-instrumentation
svrnm Sep 13, 2023
0fd13fb
Merge branch 'main' into java-manual-instrumentation
svrnm Sep 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 141 additions & 0 deletions content/en/docs/instrumentation/java/exporters.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
---
title: Exporters
weight: 50
cSpell:ignore: autoconfigure springframework
---

In order to visualize and analyze your traces, you will need to export them to a
backend such as [Jaeger](https://www.jaegertracing.io/) or
[Zipkin](https://zipkin.io/). OpenTelemetry Java provides exporters for some
common open source backends.

If you use the Java agent for
[automatic instrumentation](/docs/instrumentation/java/automatic) you can learn
how to setup exporters following the
[Agent Configuration Guide](/docs/instrumentation/java/automatic/agent-config)

For [manual instrumentation](/docs/instrumentation/java/manual), you will find
some introductions below on how to set up backends and the matching exporters.

## OTLP endpoint

To send trace data to a OTLP endpoint (like the [collector](/docs/collector) or
Jaeger) you'll want to use `opentelemetry-exporter-otlp`:
svrnm marked this conversation as resolved.
Show resolved Hide resolved

{{< tabpane text=true >}} {{% tab Gradle %}}

```kotlin
dependencies {
implementation 'io.opentelemetry:opentelemetry-exporter-otlp:{{% param javaVersion %}}'
}
```

{{% /tab %}} {{% tab Maven %}}

```xml
<project>
<dependencies>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-exporter-otlp</artifactId>
</dependency>
</dependencies>
</project>
```

{{< /tab >}} {{< /tabpane>}}

Next, configure the exporter to point at an OTLP endpoint.

If you use
[SDK auto-configuration](/docs/instrumentation/java/manual/#automatic-configuration)
all you need to do is update your environment variables:

```shell
env OTEL_EXPORTER_OTLP_ENDPOINT=http://example:4317 java -jar ./build/libs/java-simple.jar
```

Note, that in the case of exporting via OTLP you do not need to set
`OTEL_TRACES_EXPORTER`, `OTEL_METRICS_EXPORTER` and `OTEL_LOGS_EXPORTER` since
`otlp` is their default value

In the case of [manual configuration] you can update the
[example app](/docs/instrumentation/java/manual#example-app) like the following:

```java { hl_lines=["12-14",21,"39-53"] }
package otel;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.Banner;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator;
import io.opentelemetry.context.propagation.ContextPropagators;
import io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporter;
import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter;
import io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogRecordExporter;
import io.opentelemetry.sdk.OpenTelemetrySdk;
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
import io.opentelemetry.sdk.metrics.export.PeriodicMetricReader;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.trace.SdkTracerProvider;
import io.opentelemetry.sdk.trace.export.BatchSpanProcessor;
import io.opentelemetry.sdk.logs.export.BatchLogRecordProcessor;
import io.opentelemetry.sdk.logs.SdkLoggerProvider;
import io.opentelemetry.sdk.logs.export.LogRecordExporter;
import io.opentelemetry.semconv.resource.attributes.ResourceAttributes;

@SpringBootApplication
public class DiceApplication {
public static void main(String[] args) {
SpringApplication app = new SpringApplication(DiceApplication.class);
app.setBannerMode(Banner.Mode.OFF);
app.run(args);
}

@Bean
public OpenTelemetry openTelemetry() {
Resource resource = Resource.getDefault().toBuilder().put(SERVICE_NAME, "dice-server").put(SERVICE_VERSION, "0.1.0").build();

SdkTracerProvider sdkTracerProvider = SdkTracerProvider.builder()
.addSpanProcessor(BatchSpanProcessor.builder(OtlpGrpcSpanExporter.builder().build()).build())
.setResource(resource)
.build();

SdkMeterProvider sdkMeterProvider = SdkMeterProvider.builder()
.registerMetricReader(PeriodicMetricReader.builder(OtlpGrpcMetricExporter.builder().build()).build())
.setResource(resource)
.build();

SdkLoggerProvider sdkLoggerProvider = SdkLoggerProvider.builder()
.addLogRecordProcessor(
BatchLogRecordProcessor.builder(OtlpGrpcLogRecordExporter.builder().build()).build())
.setResource(resource)
.build();

OpenTelemetry openTelemetry = OpenTelemetrySdk.builder()
.setTracerProvider(sdkTracerProvider)
.setMeterProvider(sdkMeterProvider)
.setLoggerProvider(sdkLoggerProvider)
.setPropagators(ContextPropagators.create(W3CTraceContextPropagator.getInstance()))
.buildAndRegisterGlobal();

return openTelemetry;
}
}
```

To see the traces exported quickly, you can run Jaeger with OTLP enabled in a
docker container:

```shell
docker run -d --name jaeger \
-e COLLECTOR_OTLP_ENABLED=true \
-p 16686:16686 \
-p 4317:4317 \
-p 4318:4318 \
jaegertracing/all-in-one:latest
svrnm marked this conversation as resolved.
Show resolved Hide resolved
```
7 changes: 7 additions & 0 deletions content/en/docs/instrumentation/java/libraries.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: Using instrumentation libraries
linkTitle: Libraries
weight: 40
---

_to be done_
Loading