Package codes.grow.packages.datadogapm
Class DatadogTracing
java.lang.Object
codes.grow.packages.datadogapm.DatadogTracing
initTracing for Datadog: the OpenTelemetry SDK exporting OTLP to the Datadog Agent
(HTTP/protobuf on 4318 by default, or gRPC on 4317), unified service tagging, the Datadog + W3C
propagators, the Datadog error attributes and the terminated-context links (API.md section 2,
DECISIONS.md #2, #5).
try (DatadogTracingHandle tracing = DatadogTracing.initTracing(
TracingConfig.builder("checkout").environment("prod").build())) {
Spans.withSpan("charge", () -> charge(order));
}
-
Field Summary
FieldsModifier and TypeFieldDescriptionDefault propagators of this package: Datadog headers, W3C trace context and baggage. -
Method Summary
Modifier and TypeMethodDescriptionstatic io.opentelemetry.sdk.trace.export.SpanExportercreateExporter(TracingConfig config) Creates the span exporter: OTLPhttp/protobuforgrpcto the config's endpoint (default: the local Agent,http://127.0.0.1:4318/v1/tracesorhttp://127.0.0.1:4317), wrapped in aDatadogSpanExporter.static SpanExporterFactoryThe exporter factory of this package (seecreateExporter(TracingConfig)).static DatadogTracingHandleSets up tracing entirely from the environment (DatadogApmConfig.fromEnv():DD_SERVICE,DD_ENV,DD_VERSION,DD_TAGS,DD_AGENT_HOST,GROW_DATADOG_APM_*,OTEL_EXPORTER_OTLP_*).static DatadogTracingHandleinitTracing(TracingConfig config) Sets up OpenTelemetry tracing that exports to the Datadog Agent (SPEC section 5), with the environment (DatadogApmConfig) as defaults for the fieldsconfigleaves unset.static DatadogTracingHandleinitTracing(TracingConfig config, DatadogApmConfig apm) initTracing(TracingConfig)with explicit Agent/service settings instead of the environment.orderPropagators(List<String> names) Putstracecontextbeforedatadogso the Datadog propagator sees the W3C result and applies the conflict rules (Datadog wins); every other name keeps its position.static TracingConfig.BuilderA tracing config builder prefilled from aDatadogApmConfig: service name, version, environment, OTLP endpoint and protocol,DD_TAGSas resource attributes, TLS and the Datadog default propagators.
-
Field Details
-
DATADOG_DEFAULT_PROPAGATORS
Default propagators of this package: Datadog headers, W3C trace context and baggage.
-
-
Method Details
-
orderPropagators
Putstracecontextbeforedatadogso the Datadog propagator sees the W3C result and applies the conflict rules (Datadog wins); every other name keeps its position. Names are trimmed and lower-cased.- Parameters:
names- propagator names- Returns:
- the ordered names
-
exporterFactory
The exporter factory of this package (seecreateExporter(TracingConfig)).- Returns:
- factory
-
createExporter
Creates the span exporter: OTLPhttp/protobuforgrpcto the config's endpoint (default: the local Agent,http://127.0.0.1:4318/v1/tracesorhttp://127.0.0.1:4317), wrapped in aDatadogSpanExporter.- Parameters:
config- tracing config- Returns:
- exporter
- Throws:
ConfigException- for thenativeprotocol (the package exports OTLP only)
-
tracingConfig
A tracing config builder prefilled from aDatadogApmConfig: service name, version, environment, OTLP endpoint and protocol,DD_TAGSas resource attributes, TLS and the Datadog default propagators.- Parameters:
apm- Agent/service settings- Returns:
- builder
- Throws:
ConfigException- whenapmhas no service name (DD_SERVICE)
-
initTracing
Sets up tracing entirely from the environment (DatadogApmConfig.fromEnv():DD_SERVICE,DD_ENV,DD_VERSION,DD_TAGS,DD_AGENT_HOST,GROW_DATADOG_APM_*,OTEL_EXPORTER_OTLP_*).- Returns:
- handle
- Throws:
ConfigException- when the environment is invalid or names no service
-
initTracing
Sets up OpenTelemetry tracing that exports to the Datadog Agent (SPEC section 5), with the environment (DatadogApmConfig) as defaults for the fieldsconfigleaves unset. A field equal to its template default (protocolhttp/protobuf, propagatorstracecontext,baggage) counts as unset.- OTLP
http/protobuftohttp://<agent>:4318/v1/tracesby default, orgrpctohttp://<agent>:4317(the Agent needs its OTLP receiver enabled); - unified service tagging: service name / version / environment become resource
service.name/service.version/deployment.environment.name(Datadogservice,version,env), plusDD_TAGSas resource attributes; - propagators
datadog,tracecontext,baggagewhenconfigkeeps the template default list (Datadog headers win on conflict); - the Datadog error attributes and the terminated-context link (
DatadogSpanExporter).
- Parameters:
config- tracing config- Returns:
- handle
- Throws:
ConfigException- for thenativeprotocol or an invalid environment
- OTLP
-
initTracing
initTracing(TracingConfig)with explicit Agent/service settings instead of the environment.- Parameters:
config- tracing configapm- Agent/service settings (Agent host, OTLP endpoint, version, env, tags, TLS)- Returns:
- handle
- Throws:
ConfigException- for thenativeprotocol
-