Add resource_attributes support to opentelemetry section#2207
Open
movence wants to merge 2 commits into
Open
Conversation
Allow customers to set additional resource attributes at the top level of the opentelemetry section. When set, a resource processor is prepended to the front of the metrics, logs, and traces export pipelines and upserts the configured key/value pairs onto every record. - Add opentelemetry.resource_attributes to the JSON schema (string map). - Add common.GetStringMap helper and the OtelResourceAttributesKey. - Prepend resource/opentelemetry processor in the three base pipelines. - Unit tests for the helper and processor ordering, schema validation samples, and a tocwconfig golden round-trip (json/yaml/toml).
Contributor
Binary Size Reportlinux/amd64
Notable changes:
linux/arm64
windows/amd64
Investigating size changesUse go-size-analyzer to compare binaries: GOEXPERIMENT=jsonv2 go install github.com/Zxilly/go-size-analyzer/cmd/gsa@latest
gsa diff --old <baseline-binary> --new <new-binary> |
… order Address review findings on the resource_attributes feature: - Reject empty attribute keys and reserved log-routing keys (aws.log.group.name, aws.log.stream.name, aws.log.source) in the resource processor's static-attributes path, so customers cannot clobber agent-managed attributes. Key validation is done in the translator because the config schema is draft-04, under which gojsonschema does not enforce propertyNames. - Emit attributes in sorted key order for deterministic generated config. - Document in the schema that resource detection (override: true) runs after and takes precedence for auto-detected keys, so the behavior is explicit rather than silent. Adds WithReservedKeys option, unit tests for empty/reserved/sorted paths, and a dedicated resource_attributes_test.go for the pipeline helper.
movence
marked this pull request as ready for review
July 17, 2026 13:29
jefchien
reviewed
Jul 17, 2026
Contributor
There was a problem hiding this comment.
nit: Can we just add this to an existing one? We're starting to have to manage and regenerate too many sample configs.
| attributes map[string]string | ||
| factory processor.Factory | ||
| attributes map[string]string | ||
| reservedKeys []string |
Contributor
There was a problem hiding this comment.
nit: Should we just store this as a collection.Set[string]?
| } | ||
| keys = append(keys, k) | ||
| } | ||
| sort.Strings(keys) |
Contributor
There was a problem hiding this comment.
Should we use errors.Join so all errors are shown at once instead of just the first?
Comment on lines
+15
to
+19
| var reservedResourceAttributeKeys = []string{ | ||
| "aws.log.group.name", | ||
| "aws.log.stream.name", | ||
| "aws.log.source", | ||
| } |
Contributor
There was a problem hiding this comment.
This makes sense in practice, but I think we'll likely want to rename all of our internally temporary resource attributes that we use and remove. That can be done as a follow up.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds support for setting additional resource attributes at the top level of the
opentelemetrysection. When a customer setsopentelemetry.resource_attributes, aresourceprocessor is prepended to the front of each OTEL export pipeline (metrics, logs, traces) andupserts the configured key/value pairs onto every record.Example config
{ "opentelemetry": { "resource_attributes": { "team": "cloudwatch", "deployment.environment": "prod" }, "collect": { "otlp": { "grpc_endpoint": "127.0.0.1:4317", "http_endpoint": "127.0.0.1:4318" } } } }Generated pipeline (metrics/logs/traces)
Implementation
opentelemetry.resource_attributes(string map,maxProperties: 30, per-valueminLength: 1/maxLength: 1024), mirroring the existing metricsappend_dimensionsdefinition.common.OtelResourceAttributesKey+ acommon.GetStringMaphelper.resourceprocessorand itsWithAttributesoption (emitsupsertactions) — no new dependencies.Design note (precedence)
The processor is placed first, i.e. before
resourcedetection. Sinceresourcedetectionruns withoverride: true, an agent-detected attribute (e.g.cloud.region,host.id) will win over a same-named customer value. If we want the customer value to always be authoritative for detected keys, the processor should instead run afterresourcedetection(but still before the transforms). Raising this for a second opinion.The field name is centralized in a single constant, so renaming (e.g.
append_resource_attributes) is a one-line change if preferred.Testing
GetStringMap; processor isProcessors.Keys()[0]in all three base pipelines.invalid_typeerror.tocwconfiggolden round-tripotlp_otel_resource_attributes_config(json input → yaml/toml goldens). TOML is byte-identical to the baseline (OTEL-only feature); YAML diff is exactly the new processor block + its prepend to the 3 pipelines.go test+go vetclean across all touched packages.