Class OtelCollectorConfig
java.lang.Object
codes.grow.packages.otelcollector.OtelCollectorConfig
Immutable configuration of a
OtelCollectorClient and of every OTLP exporter this package
builds (traces, logs, metrics).
Build one with builder() or read it from the environment with fromEnv().
Precedence per field: explicit builder value > GROW_OPENTELEMETRY_COLLECTOR_<NAME>
> GROW_OTEL_<NAME> > per-signal OTEL_* > generic OTEL_* >
default. Map fields (headers, resource attributes) merge key by key in the same order. toString() never prints credentials.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder of the configuration. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringAlias prefix accepted afterEnvReader.DEFAULT_PREFIX(ticket wording).static final DurationDefault deadline of one OTLP export including the exporter's own retries.static final StringDefault OTLP/gRPC target (port 4317).static final DurationDefault interval of the periodic metric reader.static final StringDefaultservice.namewhen none is configured (OpenTelemetry Java default).static final StringDefault OTLP/HTTP base URL (port 4318).Every resource detector, in a fixed order (the default). -
Method Summary
Modifier and TypeMethodDescriptionstatic OtelCollectorConfig.Builderbuilder()Starts an empty builder (every field at its default).Returns the export compression.Returns the connect timeout.endpointFor(Signal signal) The export endpoint of a signal for the configured protocol: the explicit per-signal URL when set, elsegrpcUrl()for gRPC andsignalUrl(Signal)for HTTP.Returnsdeployment.environment.name.explicitSignalUrl(Signal signal) Returns the explicit per-signal URL (used as is, no path appended).Returns the deadline of one OTLP export.static OtelCollectorConfigfromEnv()Reads the configuration from the process environment.static OtelCollectorConfigReads the configuration from an explicit variable map (tests).grpcUrl()Returns the OTLP/gRPC target.headers()Returns the export headers sent with every OTLP request (auth goes here).headersFor(Signal signal) Export headers of a signal:headers()with the per-signal headers on top.Returns thehealth_checkURL (default: host ofurl(), port 13133).hooks()Returns the hooks.Values of sensitive export headers (authorization,*token*,*key*, …) that are removed from every message.logger()Returns the logger.Returns the log batch settings.booleanReturns whether logs are exported.Returns the periodic metric reader interval.booleanReturns whether metrics are exported.parseKeyValueList(String raw, String variable) Parsesk=v,k2=v2(W3C baggage style, keys and values percent-decoded) as used byOTEL_EXPORTER_OTLP_HEADERSandOTEL_RESOURCE_ATTRIBUTES.Returns the propagator names.protocol()Returns the export protocol (http/protobufby default).proxy()Returns the explicit proxy URL.Returns the per-attempt timeout of health, ping and version calls.Returns the resource attributes.Returns the resource detectors run byinitTelemetry.retry()Returns the retry policy (health, ping, version; exporter retries derive from it).booleanReturns whether JVM runtime metrics are reported.sampler()Returns the trace sampler.doubleReturns the ratio of the*traceidratiosamplers.Returnsservice.name.Resource attributes of the service:resourceAttributes()plusservice.name,service.versionanddeployment.environment.name.Returnsservice.version.signalHeaders(Signal signal) Returns the headers sent only with exports of one signal.The OTLP/HTTP URL of a signal: the explicit per-signal URL, elseurl + /v1/<signal>.Returns the internal telemetry (Prometheus) URL, such ashttp://collector:8888/metrics.tls()Returns the TLS options.Returns a builder with these values (every field counts as explicit).toString()Returns the total timeout per call including retries.The tracing settings of the traces signal: service fields, resource, endpoint, protocol, headers, sampler, propagators, batch, TLS and compression.Translates the common fields into settings of the shared HTTP transport (OTLP base URL, export headers, TLS, retries).Returns the batch span processor settings.booleanReturns whether traces are exported.url()Returns the OTLP/HTTP base URL.Returns the user agent suffix.voidvalidate()Checks URLs, timeouts, protocol, sampler, batch settings, resource detectors and TLS pairs.Returns the zpages base URL (default: host ofurl(), port 55679).
-
Field Details
-
DEFAULT_URL
Default OTLP/HTTP base URL (port 4318).- See Also:
-
DEFAULT_GRPC_URL
Default OTLP/gRPC target (port 4317).- See Also:
-
DEFAULT_EXPORT_TIMEOUT
Default deadline of one OTLP export including the exporter's own retries. -
DEFAULT_METRIC_EXPORT_INTERVAL
Default interval of the periodic metric reader. -
ALIAS_ENV_PREFIX
Alias prefix accepted afterEnvReader.DEFAULT_PREFIX(ticket wording).- See Also:
-
RESOURCE_DETECTORS
Every resource detector, in a fixed order (the default). -
DEFAULT_SERVICE_NAME
Defaultservice.namewhen none is configured (OpenTelemetry Java default).- See Also:
-
-
Method Details
-
builder
Starts an empty builder (every field at its default).- Returns:
- a new builder
-
fromEnv
Reads the configuration from the process environment.- Returns:
- the validated configuration
- Throws:
ConfigException- when a variable holds an invalid value (the message names the variable, never the value)
-
fromEnv
Reads the configuration from an explicit variable map (tests).- Parameters:
env- variable map- Returns:
- the validated configuration
-
toBuilder
Returns a builder with these values (every field counts as explicit).- Returns:
- builder copy
-
validate
public void validate()Checks URLs, timeouts, protocol, sampler, batch settings, resource detectors and TLS pairs.- Throws:
ConfigException- when a rule is violated
-
toTransportConfig
Translates the common fields into settings of the shared HTTP transport (OTLP base URL, export headers, TLS, retries).- Returns:
- the transport configuration
-
knownSecrets
Values of sensitive export headers (authorization,*token*,*key*, …) that are removed from every message.- Returns:
- the secret values
-
signalUrl
The OTLP/HTTP URL of a signal: the explicit per-signal URL, elseurl + /v1/<signal>.- Parameters:
signal- the signal- Returns:
- the URL
-
endpointFor
The export endpoint of a signal for the configured protocol: the explicit per-signal URL when set, elsegrpcUrl()for gRPC andsignalUrl(Signal)for HTTP.- Parameters:
signal- the signal- Returns:
- the endpoint
-
headersFor
Export headers of a signal:headers()with the per-signal headers on top.- Parameters:
signal- the signal- Returns:
- a new map
-
serviceResource
Resource attributes of the service:resourceAttributes()plusservice.name,service.versionanddeployment.environment.name.- Returns:
- a new map
-
toTracingConfig
The tracing settings of the traces signal: service fields, resource, endpoint, protocol, headers, sampler, propagators, batch, TLS and compression.- Returns:
- a new tracing config
-
url
Returns the OTLP/HTTP base URL.- Returns:
- the URL
-
connectTimeout
Returns the connect timeout.- Returns:
- the timeout
-
requestTimeout
Returns the per-attempt timeout of health, ping and version calls.- Returns:
- the timeout
-
totalTimeout
Returns the total timeout per call including retries.- Returns:
- the timeout
-
retry
Returns the retry policy (health, ping, version; exporter retries derive from it).- Returns:
- the policy
-
tls
Returns the TLS options.- Returns:
- the options
-
proxy
Returns the explicit proxy URL.- Returns:
- the proxy, or empty
-
headers
Returns the export headers sent with every OTLP request (auth goes here).- Returns:
- immutable map
-
userAgentSuffix
Returns the user agent suffix.- Returns:
- the suffix, or empty
-
hooks
Returns the hooks.- Returns:
- the hooks
-
logger
Returns the logger.- Returns:
- the logger
-
grpcUrl
Returns the OTLP/gRPC target.- Returns:
- the URL
-
protocol
Returns the export protocol (http/protobufby default).- Returns:
- the protocol
-
explicitSignalUrl
Returns the explicit per-signal URL (used as is, no path appended).- Parameters:
signal- the signal- Returns:
- the URL, or empty
-
signalHeaders
Returns the headers sent only with exports of one signal.- Parameters:
signal- the signal- Returns:
- immutable map
-
compression
Returns the export compression.- Returns:
- the compression
-
exportTimeout
Returns the deadline of one OTLP export.- Returns:
- the timeout
-
healthUrl
Returns thehealth_checkURL (default: host ofurl(), port 13133).- Returns:
- the URL
-
zpagesUrl
Returns the zpages base URL (default: host ofurl(), port 55679).- Returns:
- the URL
-
telemetryUrl
Returns the internal telemetry (Prometheus) URL, such ashttp://collector:8888/metrics.- Returns:
- the URL, or empty
-
serviceName
Returnsservice.name.- Returns:
- the name
-
serviceVersion
Returnsservice.version.- Returns:
- the version, or empty
-
environment
Returnsdeployment.environment.name.- Returns:
- the environment, or empty
-
resourceAttributes
Returns the resource attributes.- Returns:
- immutable map
-
tracesEnabled
public boolean tracesEnabled()Returns whether traces are exported.- Returns:
- true by default
-
logsEnabled
public boolean logsEnabled()Returns whether logs are exported.- Returns:
- true by default
-
metricsEnabled
public boolean metricsEnabled()Returns whether metrics are exported.- Returns:
- true by default
-
sampler
Returns the trace sampler.- Returns:
- the sampler
-
samplerRatio
public double samplerRatio()Returns the ratio of the*traceidratiosamplers.- Returns:
- the ratio
-
propagators
Returns the propagator names.- Returns:
- immutable list
-
tracesBatch
Returns the batch span processor settings.- Returns:
- the settings
-
logsBatch
Returns the log batch settings.- Returns:
- the options
-
metricExportInterval
Returns the periodic metric reader interval.- Returns:
- the interval
-
runtimeMetrics
public boolean runtimeMetrics()Returns whether JVM runtime metrics are reported.- Returns:
- false by default
-
resourceDetectors
Returns the resource detectors run byinitTelemetry.- Returns:
- immutable list
-
toString
-
parseKeyValueList
Parsesk=v,k2=v2(W3C baggage style, keys and values percent-decoded) as used byOTEL_EXPORTER_OTLP_HEADERSandOTEL_RESOURCE_ATTRIBUTES.- Parameters:
raw- the valuevariable- variable name for the error message- Returns:
- ordered map
- Throws:
ConfigException- namingvariable(never the value) on malformed input
-