Class OtelCollectorConfig.Builder
java.lang.Object
codes.grow.packages.otelcollector.OtelCollectorConfig.Builder
- Enclosing class:
OtelCollectorConfig
Builder of the configuration.
Unset fields take the environment (when fromEnv(EnvReader) is called) or the
default.
-
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds and validates the configuration.compression(TracingConfig.Compression compression) Sets the export compression (default gzip).Sets the connect timeout (default 10 s).environment(String environment) Setsdeployment.environment.name.exportTimeout(Duration timeout) Sets the deadline of one OTLP export including the exporter's retries (default 10 s).Fills every field that was not set explicitly from the environment:GROW_OPENTELEMETRY_COLLECTOR_*, thenGROW_OTEL_*, then the standardOTEL_*variables.Sets the OTLP/gRPC target (default: host ofurl(String), port 4317);https://enables TLS.Adds a header sent with every export and withping(for exampleAuthorization).Adds headers sent with every export.Sets thehealth_checkURL.Sets request hooks.Sets the logger (default silent).logs(boolean enabled) Turns log export on or off (default on).logsBatch(BatchOptions batch) Sets the log batch settings (OTEL_BLRP_*are then ignored).metricExportInterval(Duration interval) Sets the periodic metric reader interval (default 60 s).metrics(boolean enabled) Turns metric export on or off (default on).propagators(String... propagators) Sets the propagators.propagators(List<String> propagators) Sets the propagators (defaulttracecontext,baggage).protocol(TracingConfig.Protocol protocol) Sets the export protocol (NATIVEis rejected bybuild()).Sets the export protocol by name:grpc,http/protobufornative.Sets an explicit proxy URL for health, ping and version calls.Sets the per-attempt timeout of health, ping and version calls (default 30 s).resourceAttribute(String key, Object value) Adds one resource attribute.resourceAttributes(Map<String, ?> attributes) Adds resource attributes (explicit keys win over environment keys).resourceDetectors(List<String> detectors) Sets the resource detectors (host,process,container,k8s); an empty list disables detection.retry(RetryPolicy retry) Sets the retry policy (defaultRetryPolicy.defaults()).runtimeMetrics(boolean enabled) Turns JVM runtime metrics on or off (default off).sampler(TracingConfig.SamplerType sampler) Sets the trace sampler (defaultparentbased_always_on).samplerRatio(double ratio) Sets the ratio of the*traceidratiosamplers (default 1).serviceName(String serviceName) Setsservice.name.serviceVersion(String serviceVersion) Setsservice.version.signalHeader(Signal signal, String name, String value) Adds a header sent only with exports of one signal (merged overheader(java.lang.String, java.lang.String)).Sets the full OTLP endpoint of one signal, used as is (no path appended).telemetryUrl(String telemetryUrl) Sets the internal telemetry (Prometheus) URL used byserverVersionas fallback.tls(TlsOptions tls) Sets the TLS options; environment TLS variables are then ignored.Sets the total timeout per call including retries (default 120 s).traces(boolean enabled) Turns trace export on or off (default on).Sets the batch span processor settings (OTEL_BSP_*are then ignored).Sets the OTLP/HTTP base URL (defaulthttp://127.0.0.1:4318); signal paths are appended.userAgentSuffix(String suffix) Sets the text appended to theUser-Agent.Sets the zpages base URL.
-
Method Details
-
fromEnv
Fills every field that was not set explicitly from the environment:GROW_OPENTELEMETRY_COLLECTOR_*, thenGROW_OTEL_*, then the standardOTEL_*variables.- Parameters:
env- environment reader- Returns:
- this builder
- Throws:
ConfigException- when a variable holds an invalid value
-
url
Sets the OTLP/HTTP base URL (defaulthttp://127.0.0.1:4318); signal paths are appended.- Parameters:
url-httporhttpsURL- Returns:
- this builder
-
grpcUrl
Sets the OTLP/gRPC target (default: host ofurl(String), port 4317);https://enables TLS.- Parameters:
grpcUrl- URL- Returns:
- this builder
-
protocol
Sets the export protocol (NATIVEis rejected bybuild()).- Parameters:
protocol- protocol- Returns:
- this builder
-
protocol
Sets the export protocol by name:grpc,http/protobufornative.- Parameters:
protocol- name- Returns:
- this builder
- Throws:
ConfigException- for an unknown name ornative
-
signalUrl
Sets the full OTLP endpoint of one signal, used as is (no path appended).- Parameters:
signal- signalurl- URL- Returns:
- this builder
-
header
Adds a header sent with every export and withping(for exampleAuthorization).- Parameters:
name- header namevalue- header value- Returns:
- this builder
-
headers
Adds headers sent with every export.- Parameters:
headers- headers- Returns:
- this builder
-
signalHeader
Adds a header sent only with exports of one signal (merged overheader(java.lang.String, java.lang.String)).- Parameters:
signal- signalname- header namevalue- header value- Returns:
- this builder
-
compression
Sets the export compression (default gzip).- Parameters:
compression- compression- Returns:
- this builder
-
exportTimeout
Sets the deadline of one OTLP export including the exporter's retries (default 10 s).- Parameters:
timeout- positive duration- Returns:
- this builder
-
healthUrl
Sets thehealth_checkURL.- Parameters:
healthUrl- URL- Returns:
- this builder
-
zpagesUrl
Sets the zpages base URL.- Parameters:
zpagesUrl- URL- Returns:
- this builder
-
telemetryUrl
Sets the internal telemetry (Prometheus) URL used byserverVersionas fallback.- Parameters:
telemetryUrl- URL such ashttp://collector:8888/metrics- Returns:
- this builder
-
serviceName
Setsservice.name.- Parameters:
serviceName- name- Returns:
- this builder
-
serviceVersion
Setsservice.version.- Parameters:
serviceVersion- version- Returns:
- this builder
-
environment
Setsdeployment.environment.name.- Parameters:
environment- environment- Returns:
- this builder
-
resourceAttributes
Adds resource attributes (explicit keys win over environment keys).- Parameters:
attributes- attributes- Returns:
- this builder
-
resourceAttribute
Adds one resource attribute.- Parameters:
key- keyvalue- value- Returns:
- this builder
-
traces
Turns trace export on or off (default on).- Parameters:
enabled- on- Returns:
- this builder
-
logs
Turns log export on or off (default on).- Parameters:
enabled- on- Returns:
- this builder
-
metrics
Turns metric export on or off (default on).- Parameters:
enabled- on- Returns:
- this builder
-
sampler
Sets the trace sampler (defaultparentbased_always_on).- Parameters:
sampler- sampler- Returns:
- this builder
-
samplerRatio
Sets the ratio of the*traceidratiosamplers (default 1).- Parameters:
ratio- ratio between 0 and 1- Returns:
- this builder
-
propagators
Sets the propagators (defaulttracecontext,baggage).- Parameters:
propagators- names- Returns:
- this builder
-
propagators
Sets the propagators.- Parameters:
propagators- names- Returns:
- this builder
-
tracesBatch
Sets the batch span processor settings (OTEL_BSP_*are then ignored).- Parameters:
batch- settings- Returns:
- this builder
-
logsBatch
Sets the log batch settings (OTEL_BLRP_*are then ignored).- Parameters:
batch- options- Returns:
- this builder
-
metricExportInterval
Sets the periodic metric reader interval (default 60 s).- Parameters:
interval- positive duration- Returns:
- this builder
-
runtimeMetrics
Turns JVM runtime metrics on or off (default off).- Parameters:
enabled- on- Returns:
- this builder
-
resourceDetectors
Sets the resource detectors (host,process,container,k8s); an empty list disables detection.- Parameters:
detectors- names- Returns:
- this builder
-
connectTimeout
Sets the connect timeout (default 10 s).- Parameters:
d- positive duration- Returns:
- this builder
-
requestTimeout
Sets the per-attempt timeout of health, ping and version calls (default 30 s).- Parameters:
d- positive duration- Returns:
- this builder
-
totalTimeout
Sets the total timeout per call including retries (default 120 s).- Parameters:
d- positive duration- Returns:
- this builder
-
retry
Sets the retry policy (defaultRetryPolicy.defaults()).- Parameters:
retry- policy- Returns:
- this builder
-
tls
Sets the TLS options; environment TLS variables are then ignored.- Parameters:
tls- options- Returns:
- this builder
-
proxy
Sets an explicit proxy URL for health, ping and version calls.- Parameters:
proxy- proxy URL- Returns:
- this builder
-
userAgentSuffix
Sets the text appended to theUser-Agent.- Parameters:
suffix- suffix- Returns:
- this builder
-
hooks
Sets request hooks.- Parameters:
hooks- hooks- Returns:
- this builder
-
logger
Sets the logger (default silent).- Parameters:
logger- logger- Returns:
- this builder
-
build
Builds and validates the configuration.- Returns:
- the configuration
- Throws:
ConfigException- when a rule is violated
-