|
| 1 | +/////////////////////////////////////////////////////////////////////////////// |
| 2 | + Copyright (c) 2024, Oracle and/or its affiliates. |
| 3 | + |
| 4 | + Licensed under the Universal Permissive License v 1.0 as shown at |
| 5 | + https://oss.oracle.com/licenses/upl. |
| 6 | +/////////////////////////////////////////////////////////////////////////////// |
| 7 | += OpenTelemetry Support |
| 8 | +:description: OpenTelemetry Support |
| 9 | +:keywords: coherence, java, distrbuted-tracing, opentelemetry, documentation |
| 10 | +
|
| 11 | +// DO NOT remove this header - it might look like a duplicate of the header above, but |
| 12 | +// both they serve a purpose, and the docs will look wrong if it is removed. |
| 13 | +== OpenTelemetry Support |
| 14 | +
|
| 15 | +This version of Coherence adds support for `OpenTelemetry` in addition to `OpenTracing` |
| 16 | +as an option for distributed tracing within a Coherence cluster. |
| 17 | +
|
| 18 | +Coherence does not include any tracing implementation libraries. Therefore, the |
| 19 | +developer will need to provide the desired tracing runtime. As OpenTracing is no |
| 20 | +longer maintained, it is recommended that OpenTelemetry be used instead. |
| 21 | +A minimum of OpenTelemetry for Java version 1.29 or later is recommended. OpenTracing, |
| 22 | +while now deprecated in Coherence, is still a supported option using the latest |
| 23 | +OpenTracing 0.33.0. |
| 24 | +
|
| 25 | +== Dependencies |
| 26 | +
|
| 27 | +At a minimum, the following OpenTelemetry dependencies (version 1.29 or later) are required in order |
| 28 | +to enable support in Coherence: |
| 29 | +
|
| 30 | +* opentelemetry-api |
| 31 | +* opentelemetry-context |
| 32 | +* opentelemetry-sdk |
| 33 | +
|
| 34 | +== Configuration |
| 35 | +
|
| 36 | +If it's desirable for Coherence to manage the initialization and lifecycle |
| 37 | +of the tracing runtime, the following dependency is also required: |
| 38 | +
|
| 39 | +* opentelemetry-sdk-extension-autoconfigure |
| 40 | +
|
| 41 | +Refer to the https://github.com/open-telemetry/opentelemetry-java/tree/main/sdk-extensions/autoconfigure[documentation] for this library for details on how to configure |
| 42 | +the tracing runtime. |
| 43 | +
|
| 44 | +This will also require setting the following system property `-Dotel.java.global-autoconfigure.enabled=true` when starting Coherence |
| 45 | +(in addition to any other telemetry related properties that may be used) |
| 46 | +
|
| 47 | +In order for Coherence to generate tracing spans, edit the operational override tangosol-coherence-override.xml file |
| 48 | +and add a <tracing-config> element with a child <sampling-ratio> element. |
| 49 | +
|
| 50 | +For example: |
| 51 | +```xml |
| 52 | +<tracing-config> |
| 53 | + <sampling-ratio>0</sampling-ratio> <!-- user-initiated tracing --> |
| 54 | +</tracing-config> |
| 55 | +``` |
| 56 | +
|
| 57 | +The `coherence.tracing.ratio` system property is used to specify the tracing sampling ratio instead |
| 58 | +of using the operational override file. For example: |
| 59 | +
|
| 60 | +```bash |
| 61 | +-Dcoherence.tracing.ratio=0 |
| 62 | +``` |
| 63 | +
|
| 64 | +Tracing operates in three modes: |
| 65 | +
|
| 66 | +* `-1` - This value disables tracing. |
| 67 | +* `0` - This value enables user-initiated tracing. This means that Coherence will not initiate tracing on its own and the application should start an outer tracing span, from which Coherence will collect the inner tracing spans. If the outer tracing span is not started, the tracing activity will not be performed. |
| 68 | +* `0.01-1.0` - This range indicates the tracing span being collected. For example, a value of 1.0 will result in all spans being collected, while a value of 0.1 will result in roughly 1 out of every 10 spans being collected. |
| 69 | +
|
| 70 | +=== Externally Managed Tracer |
| 71 | +
|
| 72 | +It is possible to use a Tracer that has already been created with Coherence |
| 73 | +by simply ensuring that the Tracer is available via the `GlobalOpenTelemtry` API included |
| 74 | +with the OpenTelemetry. When this is the case, Coherence will use the available Tracer, |
| 75 | +but will not attempt to configure or close the tracer when the cluster member is terminated. |
| 76 | +
|
| 77 | +== Traced Operations |
| 78 | +
|
| 79 | +The following Coherence traced operations may be captured: |
| 80 | +
|
| 81 | +* All operations exposed by the NamedCache API when using partitioned caches. |
| 82 | +* Events processed by event listeners (such as EventInterceptor or MapListener). |
| 83 | +* Persistence operations. |
| 84 | +* CacheStore operations. |
| 85 | +* ExecutorService operations. |
| 86 | +
|
| 87 | +== User Initiated Tracing |
| 88 | +
|
| 89 | +When the sampling ratio is set to `0`, the application will be required to start a tracing |
| 90 | +span prior to invoking a Coherence operation. |
| 91 | +
|
| 92 | +```java |
| 93 | +Tracer tracer = GlobalOpenTelemetry.getTracer("your-tracer"); |
| 94 | +Span span = tracer.spanBuilder("test").startSpan(); |
| 95 | +NamedCache cache = CacheFactory.get("some-cache"); |
| 96 | +
|
| 97 | +try (Scope scope = span.makeCurrent()) |
| 98 | + { |
| 99 | + cache.put("a", "b"); |
| 100 | + cache.get("a"); |
| 101 | + } |
| 102 | +finally |
| 103 | + { |
| 104 | + span.end(); |
| 105 | + } |
| 106 | +``` |
0 commit comments