Package org.forgerock.opentelemetry
Class OpenTelemetryUtils
java.lang.Object
org.forgerock.opentelemetry.OpenTelemetryUtils
Utility class to configure OpenTelemetry tracing. Tracing is not enabled by default.
The following is an example configuration that enables tracing (using default values for everything else):
{
"tracing": {
"enabled": true
}
}
The following is an example configuration that enables tracing with some defaults overridden:
{
"tracing": {
"enabled": true,
"resourceAttributes": {
"service.instance.id": "my-instance-id-1"
},
"exporter": {
"config": {
"headers": {
"X-CUSTOM-HEADER": "custom-value"
}
},
"batch": {
"maxQueueSize": 512
}
},
"sampler": {
"type": "parentBasedTraceIdRatio",
"ratio": 25
},
"spanLimits": {
"maxNumberOfAttributesPerEvent": 128
}
}
}
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final record
Service specific configuration items to be used when setting up OpenTelemetry tracing. -
Method Summary
Modifier and TypeMethodDescriptionstatic Function<JsonValue,
io.opentelemetry.api.OpenTelemetry, JsonException> openTelemetryConfig
(String serviceName, String serviceVersion) Returns a transformation function that takes a well-defined JSON structure that represents an OpenTelemetry configuration and generates anOpenTelemetry
instance from it.static Function<JsonValue,
io.opentelemetry.api.OpenTelemetry, JsonException> openTelemetryConfig
(OpenTelemetryUtils.ServiceConfig serviceConfig) Returns a transformation function that takes a well-defined JSON structure that represents an OpenTelemetry configuration and generates anOpenTelemetry
instance from it.static void
setSpanAttributes
(io.opentelemetry.api.trace.Span span, Request request, Context context) Configures the span attributes with data from the given request and context.static String
Computes a span name based on the giveRequest
.
-
Method Details
-
openTelemetryConfig
public static Function<JsonValue,io.opentelemetry.api.OpenTelemetry, openTelemetryConfigJsonException> (String serviceName, String serviceVersion) Returns a transformation function that takes a well-defined JSON structure that represents an OpenTelemetry configuration and generates anOpenTelemetry
instance from it.- Parameters:
serviceName
- The service name to use as a resource attribute for theServiceAttributes.SERVICE_NAME
property, for example IG. The value will be converted to lowercase before use.serviceVersion
- The service version to use as a resource attribute for theServiceAttributes.SERVICE_VERSION
property.- Returns:
- A transformation function that takes a well-defined JSON structure that represents an OpenTelemetry
configuration and generates an
OpenTelemetry
instance from it.
-
openTelemetryConfig
public static Function<JsonValue,io.opentelemetry.api.OpenTelemetry, openTelemetryConfigJsonException> (OpenTelemetryUtils.ServiceConfig serviceConfig) Returns a transformation function that takes a well-defined JSON structure that represents an OpenTelemetry configuration and generates anOpenTelemetry
instance from it.- Parameters:
serviceConfig
- Service specific configuration items to be used when setting up OpenTelemetry tracing.- Returns:
- A transformation function that takes a well-defined JSON structure that represents an OpenTelemetry
configuration and generates an
OpenTelemetry
instance from it.
-
spanName
Computes a span name based on the giveRequest
.The span name returned aims to follow the guidelines recommended by the OpenTelemetry naming conventions (see here and there).
For instance, an HTTP GET request onto the url
http://foo.com/bar/baz
gives the span nameGET /bar
.- Parameters:
request
- the request used to build the span name.- Returns:
- a span name.
-
setSpanAttributes
public static void setSpanAttributes(io.opentelemetry.api.trace.Span span, Request request, Context context) Configures the span attributes with data from the given request and context.- Parameters:
span
- the span to configurerequest
- the request used to set some attributes of the given spancontext
- the context used to set some attributes of the given span
-