Skip to content

Commit

Permalink
add explanation
Browse files Browse the repository at this point in the history
  • Loading branch information
dmuelle committed Sep 16, 2024
1 parent f680b41 commit 5561f4f
Showing 1 changed file with 24 additions and 39 deletions.
63 changes: 24 additions & 39 deletions modules/ROOT/pages/telemetry-trace.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,6 @@ With automatic instrumentation, you can observe traces without modifying the sou

In Open Liberty version 23.0.0.11 and later, spans are automatically generated for incoming HTTP requests, including static files, servlets, and JSPs.

////
To start emitting traces with automatic instrumentation, enable the MicroProfile Telemetry feature in your `server.xml` file by adding `<feature>mpTelemetry-1.0</feature>` or `<feature>mpTelemetry-1.1</feature>` to your server.xml file. By default, MicroProfile Telemetry tracing is off. To enable tracing, specify the `otel.sdk.disabled=false` MicroProfile Config property and any exporter configuration that your tracing service requires.

For example, to export traces to a Jaeger server with the OpenTelemetry Protocol (OTLP) enabled, add the following entries to your `bootstrap.properties` file.

[source,properties]
----
otel.sdk.disabled=false
otel.traces.exporter=otlp
otel.exporter.otlp.endpoint=http://localhost:4317/
----

To export traces to a Zipkin server, you can use the following properties instead:

[source,properties]
----
otel.sdk.disabled=false
otel.traces.exporter=zipkin
otel.exporter.zipkin.endpoint=http://localhost:9411/api/v2/spans
----
////

[#manual]
== Manual instrumentation

Expand All @@ -72,6 +50,27 @@ public String myMethod() {
}
----

- Annotate methods in any Jakarta CDI beans by using the `@WithSpan` annotation. This annotation creates a new Span and establishes any required relationships with the current trace context. You can annotate method parameters with the `@SpanAttribute` annotation to indicate which method parameters are part of the trace, as shown in the following example.
+
[source,java]
----
@ApplicationScoped
class SpanBean {
@WithSpan("name")
void spanName() {
...
}
@WithSpan
void spanArgs(@SpanAttribute(value = "arg") String arg) {
...
}
}
----

However, it is not possible to create a child span with the `@WithSpan` annotation by calling an internal method in the same class as the parent span. Instead, you can manually create a subspan in the child method, as shown in the next example.

- Create a subspan around a particular operation, such as querying a database. This subspan shows you how long it took and the order in which it occurred relative to other spans.
+
[source,java]
Expand All @@ -91,24 +90,10 @@ public String myMethod() {
}
----

- Annotate methods in any Jakarta CDI beans by using the `@WithSpan` annotation. This annotation creates a new Span and establishes any required relationships with the current trace context. You can annotate method parameters with the `@SpanAttribute` annotation to indicate which method parameters are part of the trace, as shown in the following example.
+
[source,java]
----
@ApplicationScoped
class SpanBean {
This example creates a span named `QueryDatabase` that can be used to track the execution time and other attributes of the `queryDatabase()` method.

@WithSpan("name")
void spanName() {
...
}
@WithSpan
void spanArgs(@SpanAttribute(value = "arg") String arg) {
...
}
}
----
// Assisted by WCA@IBM
// Latest GenAI contribution: ibm/granite-8b-code-instruct

=== Considerations for manual instrumentation

Expand Down

0 comments on commit 5561f4f

Please sign in to comment.