Package org.forgerock.opentelemetry
Class OpenTelemetryUtils
java.lang.Object
org.forgerock.opentelemetry.OpenTelemetryUtils
Utility class to configure OpenTelemetry tracing and logging. OTel tracing and logging are 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 and logging 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
}
},
"logging": {
"enabled": true,
"resourceAttributes": {
"service.instance.id": "my-instance-id-1"
},
"exporter": {
"config": {
"endpoint": "http://localhost:4318/v1/logs",
"headers": {
"X-CUSTOM-HEADER": "custom-value"
}
},
"batch": {
"maxExportBatchSize": 512
}
}
}
}
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordService 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 anOpenTelemetryinstance 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 anOpenTelemetryinstance from it.static voidsetSpanAttributes(io.opentelemetry.api.trace.Span span, Request request, Context context) Deprecated, for removal: This API element is subject to removal in a future version.static voidsetSpanRequestAttributes(io.opentelemetry.api.trace.Span span, Request request, Context context) Configures the span attributes with data from the given request and context.static voidsetSpanResponseAttributes(io.opentelemetry.api.trace.Span span, Response response) Configures the span attributes with data from the given response.static StringComputes 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 anOpenTelemetryinstance from it.- Parameters:
serviceName- The service name to use as a resource attribute for theServiceAttributes.SERVICE_NAMEproperty, 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_VERSIONproperty.- Returns:
- A transformation function that takes a well-defined JSON structure that represents an OpenTelemetry
configuration and generates an
OpenTelemetryinstance 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 anOpenTelemetryinstance 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
OpenTelemetryinstance 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/bazgives the span nameGET /bar.- Parameters:
request- the request used to build the span name.- Returns:
- a span name.
-
setSpanAttributes
@Deprecated(forRemoval=true) public static void setSpanAttributes(io.opentelemetry.api.trace.Span span, Request request, Context context) Deprecated, for removal: This API element is subject to removal in a future version.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
-
setSpanRequestAttributes
public static void setSpanRequestAttributes(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
-
setSpanResponseAttributes
public static void setSpanResponseAttributes(io.opentelemetry.api.trace.Span span, Response response) Configures the span attributes with data from the given response.- Parameters:
span- the span to configureresponse- the response used to set some attributes of the given span
-
setSpanRequestAttributes(Span, Request, Context)