Skip to content

Commit 04ea177

Browse files
authored
Revise documentation for MicroProfile Telemetry 2.1
Updated sections on telemetry data exporting, metrics, and logs. Added new content for MicroProfile Telemetry 2.1 features.
1 parent e83574a commit 04ea177

1 file changed

Lines changed: 149 additions & 28 deletions

File tree

modules/ROOT/pages/chapter09/index.adoc

Lines changed: 149 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@ In this chapter, we will explore the fundamentals of MicroProfile Telemetry, cov
1616
** Correlation
1717
* Instrumenting OpenTelemetry
1818
* Tools for Trace Analysis
19-
* Exporting the Traces
19+
* Exporting Telemetry Data
2020
* Types of Telemetry
21+
* Metrics
22+
* Logs
2123
* Agent Instrumentation
2224
* Analyzing Traces
2325
* Security Considerations for Tracing
26+
* What's New in MicroProfile Telemetry 2.1
2427

2528
== Introduction to MicroProfile Telemetry
2629

@@ -105,7 +108,8 @@ To enable tracing and exporting of telemetry data, include the MicroProfile Tele
105108
<dependency>
106109
<groupId>org.eclipse.microprofile.telemetry</groupId>
107110
<artifactId>microprofile-telemetry-api</artifactId>
108-
<version>1.1</version>
111+
<type>pom</type>
112+
<version>2.1</version>
109113
<scope>provided</scope>
110114
</dependency>
111115
----
@@ -234,57 +238,66 @@ One of Tempo’s key advantages is its tight integration with Grafana dashboards
234238
== Exporting the Traces
235239

236240
To export the traces we need to configure the exporter type and endpoint in the `src/main/resources/META-INF/microprofile-config.properties`.
237-
For using OTLP (OpenTelemetry Protocol) export, you need to add the following configuration in:
241+
MicroProfile Telemetry 2.0 and later require you to configure exporters for all three signal types: traces, metrics, and logs.
242+
For OTLP (OpenTelemetry Protocol) export, add the following configuration:
238243

239244
[source]
240245
----
241-
# Enable OpenTelemetry
242-
otel.traces.exporter=otlp
246+
# Enable OpenTelemetry
247+
otel.sdk.disabled=false
243248
244-
# Set the OTLP exporter endpoint
245-
otel.exporter.otlp.endpoint=http://localhost:4317
249+
# Set the OTLP exporter endpoint (gRPC default: port 4317)
250+
otel.exporter.otlp.endpoint=http://<hostname>:4317
246251
247252
# Define the service name
248-
otel.service.name=payment-service
253+
otel.service.name=payment-service
249254
250-
# Sampling rate: (1.0 = always, 0.5 = 50%, 0.0 = never)
255+
# Sampling: parentbased_always_on is the default
251256
otel.traces.sampler=parentbased_always_on
252257
----
253258

254-
This sends traces directly to a observability tool, enabling real-time distributed tracing and performance monitoring. To ensure proper tracing, your observability tool (for e.g. Jaeger) must be running to receive trace data.
259+
Configure signal-specific exporters only when you need to override the shared OTLP endpoint or protocol:
260+
261+
[source]
262+
----
263+
# Traces exporter (default: otlp)
264+
otel.traces.exporter=otlp
265+
266+
# Metrics exporter (default: otlp)
267+
otel.metrics.exporter=otlp
268+
269+
# Logs exporter (default: otlp)
270+
otel.logs.exporter=otlp
271+
----
272+
273+
This configuration sends telemetry data directly to an observability backend, enabling real-time distributed tracing, metrics collection, and log correlation. Ensure that the observability backend (for example, Jaeger for traces, or Grafana with Tempo and Loki) is running to receive telemetry data.
255274

256-
Using OTLP is advantageous because it is the native standard for OpenTelemetry, ensuring seamless integration with a wide range of observability tools. One of its key benefits is that it allows developers to use multiple observability platforms without changing instrumentation, providing a unified and vendor-neutral tracing solution.
275+
OTLP is the native standard for OpenTelemetry. It allows you to use multiple observability platforms without changing instrumentation, providing a unified, vendor-neutral telemetry solution.
257276

258277
=== Verify the Traces
259278

260-
Once tracing is enabled and the appropriate exporter is configured, the next step is to verify that traces are being captured and sent to the observability backend. This ensures that the MicroProfile Telemetry setup is functioning correctly and that distributed tracing data is available for monitoring and debugging.
279+
After you enable tracing and configure the exporter, verify that the traces are being captured and sent to the observability backend. This step confirms that the MicroProfile Telemetry setup functions correctly and that distributed tracing data is available for monitoring and debugging.
261280

262281
==== Run Jaeger
263282

264-
The simplest way to run Jaeger is with Docker using the command as below:
283+
Run Jaeger using Docker with OTLP support:
265284

266285
[source, bash]
267286
----
268287
docker run -d --name jaeger \
269-
-e COLLECTOR_ZIPKIN_HTTP_PORT=9411 \
270-
-p 5775:5775/udp \
271-
-p 6831:6831/udp \
272-
-p 6832:6832/udp \
273-
-p 5778:5778 \
274288
-p 16686:16686 \
275-
-p 14268:14268 \
276-
-p 14250:14250 \
277-
-p 9411:9411 \
289+
-p 4317:4317 \
290+
-p 4318:4318 \
278291
jaegertracing/all-in-one:latest
279292
----
280293

281-
The above command runs the *all-in-one* Jaeger container, which includes the agent, collector, query service, and UI.
294+
The above command runs the *all-in-one* Jaeger container, which includes the agent, collector, query service, and UI, with native OTLP support on ports 4317 (gRPC) and 4318 (HTTP/protobuf).
282295

283-
The Jaeger UI can be accessed at: `https://<hostname>:16686`.
296+
Access the Jaeger UI at `http://<hostname>:16686`.
284297

285-
Ensure all the services of our MicroProfile E-commerce applications are running.
298+
Ensure all the services of the MicroProfile E-commerce application are running.
286299

287-
Search using parameters like operation name, time range, or service for the traces associated with different microservices and confirm that the telemetry data is visible.
300+
Search using parameters such as operation name, time range, or service name for the traces associated with different microservices, and confirm that the telemetry data is visible.
288301
View a detailed breakdown of each span within the trace, including timing and attributes.
289302

290303
== Types of Telemetry
@@ -417,7 +430,101 @@ One of the key advantages of agent-based instrumentation is that it requires no
417430
Refer to the https://opentelemetry.io/docs/zero-code/java/agent/getting-started/[OpenTelemetry Java Agent Getting Started page] for step-by-step instructions on enabling it for your application.
418431
Once enabled, the agent automatically instruments the application, seamlessly integrating with distributed tracing systems without requiring developer intervention. This makes it an efficient and non-intrusive way to implement observability in MicroProfile applications.
419432

420-
Once enabled, the agent automatically instruments the application, seamlessly integrating with distributed tracing systems without requiring developer intervention. This makes it an efficient and non-intrusive way to implement observability in MicroProfile applications.
433+
== Metrics
434+
435+
Metrics are captured measurements of an application's and runtime's behavior. An application can define custom metrics in addition to the required metrics provided by the runtime.
436+
437+
=== Access to the OpenTelemetry Metrics API
438+
439+
MicroProfile Telemetry MUST provide the following CDI bean for supporting contextual instance injection:
440+
441+
* `io.opentelemetry.api.metrics.Meter`
442+
443+
Inject the `Meter` to define and record custom metrics:
444+
445+
[source, java]
446+
----
447+
import io.opentelemetry.api.metrics.LongCounter;
448+
import io.opentelemetry.api.metrics.Meter;
449+
import io.opentelemetry.api.common.Attributes;
450+
import io.opentelemetry.api.common.AttributeKey;
451+
import jakarta.annotation.PostConstruct;
452+
import jakarta.enterprise.context.ApplicationScoped;
453+
import jakarta.inject.Inject;
454+
455+
@ApplicationScoped
456+
public class SubscriptionService {
457+
458+
@Inject
459+
Meter meter;
460+
461+
private LongCounter subscriptionCounter;
462+
463+
@PostConstruct
464+
public void init() {
465+
subscriptionCounter = meter
466+
.counterBuilder("new_subscriptions")
467+
.setDescription("Number of new subscriptions")
468+
.setUnit("1")
469+
.build();
470+
}
471+
472+
public void subscribe(String plan) {
473+
subscriptionCounter.add(1,
474+
Attributes.of(AttributeKey.stringKey("plan"), plan));
475+
}
476+
}
477+
----
478+
479+
The `Meter` instance creates instruments such as counters and histograms. The runtime computes separate aggregations for each unique combination of attributes.
480+
481+
=== Required Metrics
482+
483+
Runtimes MUST provide the following metrics, as defined in the OpenTelemetry Semantic Conventions.
484+
485+
.Required HTTP server metric
486+
[options="header"]
487+
|===
488+
|Metric Name |Type
489+
|`http.server.request.duration` |Histogram
490+
|===
491+
492+
.Required JVM metrics
493+
[options="header"]
494+
|===
495+
|Metric Name |Type
496+
|`jvm.memory.used` |UpDownCounter
497+
|`jvm.memory.committed` |UpDownCounter
498+
|`jvm.memory.limit` |UpDownCounter
499+
|`jvm.memory.used_after_last_gc` |UpDownCounter
500+
|`jvm.gc.duration` |Histogram
501+
|`jvm.thread.count` |UpDownCounter
502+
|`jvm.class.loaded` |Counter
503+
|`jvm.class.unloaded` |Counter
504+
|`jvm.class.count` |UpDownCounter
505+
|`jvm.cpu.time` |Counter
506+
|`jvm.cpu.count` |UpDownCounter
507+
|`jvm.cpu.recent_utilization` |Gauge
508+
|===
509+
510+
Metrics are activated whenever MicroProfile Telemetry is enabled with `otel.sdk.disabled=false`.
511+
512+
== Logs
513+
514+
The OpenTelemetry Logs bridge API enables existing log frameworks (such as SLF4J, Log4j, JUL, and Logback) to emit logs through OpenTelemetry. This specification does not define new Log APIs. The Logs bridge API is used by runtimes, not directly by application code. Therefore, this specification does not expose any Log APIs to applications.
515+
516+
Log output from an application is automatically bridged to the configured OpenTelemetry SDK instance when MicroProfile Telemetry is enabled. Configure the logs exporter in `microprofile-config.properties`:
517+
518+
[source, properties]
519+
----
520+
otel.sdk.disabled=false
521+
otel.logs.exporter=otlp
522+
otel.exporter.otlp.endpoint=http://<hostname>:4317
523+
----
524+
525+
When a log record is emitted from an application, the runtime bridges it to the configured OpenTelemetry SDK instance, which then exports it using the configured log exporter (for example, via OTLP). When an active trace context exists, the log record automatically includes the `traceId` and `spanId`, enabling correlation between logs and traces.
526+
527+
Logs are activated whenever MicroProfile Telemetry is enabled with `otel.sdk.disabled=false`.
421528

422529
== Analyzing Traces
423530

@@ -528,7 +635,6 @@ To prevent unauthorized access during transmission, ensure that telemetry data i
528635

529636
[source, properties]
530637
----
531-
otel.exporter.jaeger.endpoint=https://secure-jaeger-collector.example.com
532638
otel.exporter.otlp.endpoint=https://secure-collector.example.com
533639
----
534640

@@ -563,7 +669,7 @@ Random sampling to limiting the amount of trace data collected:
563669
[source, properties]
564670
----
565671
otel.traces.sampler=traceidratio
566-
otel.traces.sampler.traceidratio=0.1
672+
otel.traces.sampler.arg=0.1
567673
----
568674

569675
=== Compliance with Regulations
@@ -593,6 +699,21 @@ Tracing can help detect potential security incidents. Monitor traces for unusual
593699
Set up alerts for these anomalies to investigate and mitigate potential issues. +
594700
By following these security considerations, you can leverage the benefits of distributed tracing without compromising the security of your system or the privacy of your users. Careful handling of trace data, coupled with robust encryption, access controls, and compliance practices, ensures that tracing remains a valuable yet secure component of your observability strategy.
595701

702+
== What's New in MicroProfile Telemetry 2.1
703+
704+
MicroProfile Telemetry 2.1 is aligned with MicroProfile 7.1. The following changes are delivered in this release.
705+
706+
* MicroProfile Telemetry 2.1 consumes https://github.com/open-telemetry/opentelemetry-java/releases/tag/v1.48.0[OpenTelemetry Java v1.48.0].
707+
* If you are migrating from earlier version of MicroProfile Telemetry, update the `microprofile-telemetry-api` dependency version to `2.1`.
708+
* Verify that your deployment environment provides the OpenTelemetry Java v1.48.0 libraries or a later patch version.
709+
* The stabilization of HTTP semantic conventions (attributes such as `http.method` have been renamed to `http.request.method`).
710+
* The introduction of a single shared OpenTelemetry SDK instance when `otel.sdk.disabled=false` is configured at runtime initialization time.
711+
* The addition of Metrics and Logs support.
712+
713+
=== Impact on Existing Applications
714+
715+
Applications that do not use JVM metrics are unaffected by the 2.1 changes. Applications relying on JVM metrics should update their `microprofile-telemetry-api` dependency version to 2.1 to benefit from the corrected JVM metrics configuration.
716+
596717
== Conclusion
597718

598719
MicroProfile Telemetry provides a robust foundation for observability in Java-based microservices, enabling developers to implement distributed tracing seamlessly. By leveraging this specification, you can gain deep insights into the flow of requests, identify bottlenecks, and enhance the reliability and performance of your applications. The integration of standardized tracing concepts like spans, traces, and context propagation ensures that developers can maintain a cohesive understanding of their system's behavior across service boundaries.

0 commit comments

Comments
 (0)