Skip to content

Commit da71e9e

Browse files
Merge pull request #361 from programmatix/release/3.4
Tidying the OpenTelemtry documentation
2 parents b5b8276 + 0c02bd6 commit da71e9e

File tree

2 files changed

+19
-70
lines changed

2 files changed

+19
-70
lines changed

modules/howtos/examples/Tracing.java

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,6 @@ public static void main(String... args) throws Exception {
3232
CoreEnvironment environment = CoreEnvironment.builder().thresholdLoggingTracerConfig(config).build();
3333
// end::tracing-configure[]
3434
}
35-
36-
{
37-
// tag::otel-configure[]
38-
// Create a channel towards Jaeger end point
39-
ManagedChannel jaegerChannel = ManagedChannelBuilder.forAddress("localhost", 14250).usePlaintext().build();
40-
41-
// Export traces to Jaeger
42-
JaegerGrpcSpanExporter jaegerExporter = JaegerGrpcSpanExporter.builder().setServiceName("YOUR_SERVICE_NAME_HERE")
43-
.setChannel(jaegerChannel).setDeadlineMs(30000).build();
44-
45-
// Set to process the spans by the Jaeger Exporter
46-
OpenTelemetrySdk.getGlobalTracerManagement()
47-
.addSpanProcessor(SimpleSpanProcessor.builder(jaegerExporter).build());
48-
// end::otel-configure[]
49-
50-
// tag::otel-configure-setup[]
51-
// Wrap Tracer
52-
RequestTracer tracer = OpenTelemetryRequestTracer.wrap(OpenTelemetry.get());
53-
54-
ClusterEnvironment environment = ClusterEnvironment.builder().requestTracer(tracer).build();
55-
// end::otel-configure-setup[]
56-
}
5735
}
5836
}
5937

@@ -68,12 +46,16 @@ public static void opentelemetryDirect() {
6846
.setResource(Resource.getDefault()
6947
.merge(Resource.builder()
7048
// An OpenTelemetry service name generally reflects the name of your microservice,
71-
// e.g. "shopping-cart-service"
49+
// e.g. "shopping-cart-service".
7250
.put("service.name", "YOUR_SERVICE_NAME_HERE")
7351
.build()))
52+
// The BatchSpanProcessor will efficiently batch traces and periodically export them.
53+
// This exporter exports traces on the OTLP protocol over GRPC on port 4317.
7454
.addSpanProcessor(BatchSpanProcessor.builder(OtlpGrpcSpanExporter.builder()
7555
.setEndpoint("HOSTNAME_OF_OPENTELEMETRY_BACKEND:4317")
7656
.build()).build())
57+
// Export every trace: this may be too heavy for production.
58+
// An alternative is `.setSampler(Sampler.traceIdRatioBased(0.01))`
7759
.setSampler(Sampler.alwaysOn())
7860
.build();
7961

modules/howtos/pages/observability-tracing.adoc

Lines changed: 14 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ More information will be provided as we get closer to stabilization.
7272
The built-in tracer is great if you do not have a centralized monitoring system, but if you already plug into the OpenTelemetry ecosystem we want to make sure to provide first-class support.
7373

7474
=== Exporting to OpenTelemetry
75-
This method exports tracing telemetry in OpenTelemetry's standard format (OTLP), which can be sent to any OTLP-compatible backend/processor such as Jaeger, Zipkin or `opentelemetry-collector`.
75+
This method exports tracing telemetry in OpenTelemetry's standard format (OTLP), which can be sent to any OTLP-compatible receiver such as Jaeger, Zipkin or `opentelemetry-collector`.
7676

7777
Add this to your Maven, or the equivalent to your build tool of choice:
7878

@@ -122,53 +122,20 @@ And now:
122122
include::example$Tracing.java[tag=otel-direct,indent=0]
123123
----
124124

125-
=== Exporting directly to Jaeger
126-
This example outputs tracing telemetry from the SDK directly to Jaeger, or a Jaeger-compatible backend such as Zipkin.
125+
At this point the SDK will automatically be exporting spans, and you should see them in your receiver of choice.
127126

128-
Add this to your Maven, or the equivalent to your build tool of choice:
129-
130-
[source,xml]
131-
----
132-
<dependency>
133-
<groupId>com.couchbase.client</groupId>
134-
<artifactId>tracing-opentelemetry</artifactId>
135-
<version>1.2.0</version>
136-
</dependency>
137-
<dependency>
138-
<groupId>io.opentelemetry</groupId>
139-
<artifactId>opentelemetry-exporter-jaeger</artifactId>
140-
<version>0.11.0</version>
141-
</dependency>
142-
<dependency>
143-
<groupId>io.grpc</groupId>
144-
<artifactId>grpc-protobuf</artifactId>
145-
<version>1.28.0</version>
146-
</dependency>
147-
<dependency>
148-
<groupId>io.grpc</groupId>
149-
<artifactId>grpc-netty-shaded</artifactId>
150-
<version>1.28.0</version>
151-
</dependency>
152-
----
153-
154-
Next up, initialize the jaeger tracer:
155-
156-
[source,java]
157-
----
158-
include::example$Tracing.java[tag=otel-configure,indent=0]
159-
----
160-
161-
Once the exporter is set up, it can be wrapped into the `OpenTelemetryRequestTracer` and passed into the environment.
162-
163-
[source,java]
164-
----
165-
include::example$Tracing.java[tag=otel-configure-setup,indent=0]
166-
----
167-
168-
=== Span output
169-
At this point, whichever method you have used, the SDK will automatically be exporting spans and you should see them in your backend of choice.
127+
=== OpenTelemetry Troubleshooting
170128

171-
(Bear in mind during testing that the exporter may batch spans and hence not export them if the application exits quickly enough. This can be configured on the `BatchSpanProcessor` or `JaegerGrpcSpanExporter` objects.)
129+
* There are many ways to export spans.
130+
The example is exporting OpenTelemetry Protocol (OTLP) spans over GRPC to port 4317, which we believe is the _de facto_ standard for OpenTelemetry.
131+
Make sure that your receiver is compatible with this, e.g. has these ports open and is ready to receive OTLP traffic over GRPC.
132+
With https://www.jaegertracing.io/docs/1.41/getting-started/[Jaeger in Docker] this is achieved with the options `-e COLLECTOR_OTLP_ENABLED=true` and `-p 4317:4317`.
133+
* The exporter used in this example is `BatchSpanProcessor`, which may not have a chance to export spans if the application exits very quickly (e.g. a test application).
134+
`SimpleSpanProcessor` can be used instead, though is not likely suitable for production.
135+
* The example above uses `Sampler.alwaysOn()`, which exports every span.
136+
This may need to be reduced to avoid overwhelming the receiver, with e.g. `Sampler.traceIdRatioBased(0.01)` to sample 1% of all traces.
137+
* It can be worth sending traces into https://opentelemetry.io/docs/collector/[OpenTelemetry Collector], and forwarding them on from there to your receiver of choice.
138+
Among other capabilities the collector can log traces it receives, making for easier debugging.
172139

173140
=== Parent spans
174141

@@ -199,7 +166,7 @@ You need to include the `tracing-opentracing` module:
199166
</dependency>
200167
----
201168

202-
And then wrap the Tracer:
169+
And then create an OpenTracing `Tracer` and pass it to the SDK:
203170

204171
[source,java]
205172
----

0 commit comments

Comments
 (0)