Add resource attributes to Datadog OtelCollector payload #5288
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.
PR by Bits for Dev Agent Session
You can ask for changes by mentioning @DataDog in a comment.
Feedback (especially what can be better) welcome in #code-gen-feedback!
Description
This change adds a new field
collector_resource_attributesto theOtelCollectorstruct in the internal payload, which is populated with resource attributes fromTelemetrySettings.Resource. The resource attributes are formatted as a list of strings in the format["key1:value1", "key2:value2"...]and sorted alphabetically by key for consistency.The implementation follows the pattern used in
extension/opampextension/opamp_agent.gofor accessing and storing resource attributes.Link to tracking issue
Fixes
Testing
Added comprehensive test coverage:
TestCollectorResourceAttributesArePopulated()verifies that resource attributes are correctly collected from TelemetrySettings, sorted alphabetically, and stored in the extensionTestOtelCollectorResourceAttributesJSON()validates that the resource attributes are properly serialized and deserialized in JSON payloadsDocumentation
The field is self-documenting through the code comments explaining the format and source of the resource attributes.