Skip to content

[pkg/ottl] Add client metadata access to OTTL contexts#41879

Merged
evan-bradley merged 65 commits intoopen-telemetry:mainfrom
ronkorland:metadata-context
Feb 28, 2026
Merged

[pkg/ottl] Add client metadata access to OTTL contexts#41879
evan-bradley merged 65 commits intoopen-telemetry:mainfrom
ronkorland:metadata-context

Conversation

@ronkorland
Copy link
Copy Markdown
Contributor

Description

This PR adds metadata access capability to all OTTL (OpenTelemetry Transformation Language) contexts, enabling users to access client request metadata within OTTL transformations.

What this achieves:

  • Adds new metadata path expression to access the entire client metadata object
  • Adds metadata["key"] path expression to access specific metadata values by key
  • Available in all OTTL contexts (span, log, metric, resource, datapoint, scope, spanevent, profile, profilesample)
  • Enables access to HTTP headers, authentication tokens, and other client metadata from incoming requests
  • Supports filtering, routing, and enrichment use cases based on request metadata

Implementation details:

  • Created new ctxmetadata package with path expression parser
  • Integrated metadata access into the common OTTL context parser
  • Returns client.Metadata type for full metadata access
  • Returns string or nil for specific key access (first value if multiple exist)
  • Read-only access (metadata cannot be modified via OTTL)

Link to tracking issue

Fixes #33288

Testing

  • Added comprehensive unit tests in pkg/ottl/contexts/internal/ctxmetadata/metadata_test.go
  • Tests cover accessing entire metadata object and specific keys
  • Tests validate behavior with empty keys, non-existent keys, and multi-value scenarios
  • Tests verify error handling for invalid access patterns
  • All existing OTTL context tests continue to pass

Documentation

  • Updated README files for all OTTL contexts to document the new metadata paths:
    • pkg/ottl/contexts/ottldatapoint/README.md
    • pkg/ottl/contexts/ottllog/README.md
    • pkg/ottl/contexts/ottlmetric/README.md
    • pkg/ottl/contexts/ottlprofile/README.md
    • pkg/ottl/contexts/ottlprofilesample/README.md
    • pkg/ottl/contexts/ottlresource/README.md
    • pkg/ottl/contexts/ottlscope/README.md
    • pkg/ottl/contexts/ottlspan/README.md
    • pkg/ottl/contexts/ottlspanevent/README.md
  • Each README now includes:
    • metadata path description and return type (client.Metadata)
    • metadata[""] path description and return type (string or nil)
    • Clear explanation of behavior for missing keys and multiple values

Add `metadata` and `metadata["key"]` path expressions to access
client request metadata in all OTTL transformation contexts.

Fixes open-telemetry#33288
Comment thread pkg/ottl/contexts/internal/ctxcommon/parser.go Outdated
@edmocosta
Copy link
Copy Markdown
Contributor

Thanks for the help with the renaming and conflict resolution, @edmocosta! I've reviewed the changes and they look good. Please let me know if there's anything else needed on my end to move this forward

Thanks @ronkorland, I've addressed the final suggestions I had, one adapting the transform context to use pointer (recent standard changes), added some security and best practices section on the docs, and finally a feature gate to temporarily allow users to disable the new context access, see 3685ffa and 50be0be.
Could you please take a look on both commits?

@TylerHelmuth @evan-bradley, it looks good to me, please have a final look so we can finally move this feature forward. Thank you!

…y-collector-contrib into metadata-context

# Conflicts:
#	connector/countconnector/go.mod
#	connector/signaltometricsconnector/go.mod
#	connector/signaltometricsconnector/go.sum
#	connector/sumconnector/go.mod
#	connector/sumconnector/go.sum
#	internal/filter/go.mod
#	internal/filter/go.sum
#	pkg/ottl/go.mod
#	pkg/ottl/go.sum
#	processor/filterprocessor/go.mod
#	processor/filterprocessor/go.sum
#	processor/logdedupprocessor/go.mod
#	processor/logdedupprocessor/go.sum
#	processor/lookupprocessor/go.mod
#	processor/lookupprocessor/go.sum
#	processor/spanprocessor/go.mod
#	processor/spanprocessor/go.sum
#	processor/tailsamplingprocessor/go.mod
#	processor/tailsamplingprocessor/go.sum
#	processor/transformprocessor/go.mod
#	processor/transformprocessor/go.sum
@ronkorland
Copy link
Copy Markdown
Contributor Author

@edmocosta thanks for the ping. I have reviewed the latest changes in 3685ffa and 50be0be. The security documentation and the feature gate are excellent additions. I'm aligned with these updates and ready for the code owners' final review

@edmocosta
Copy link
Copy Markdown
Contributor

/easycla

…y-collector-contrib into metadata-context

# Conflicts:
#	connector/countconnector/go.mod
#	connector/signaltometricsconnector/go.mod
#	connector/signaltometricsconnector/go.sum
#	connector/sumconnector/go.mod
#	connector/sumconnector/go.sum
#	internal/filter/go.mod
#	internal/filter/go.sum
#	pkg/ottl/go.mod
#	pkg/ottl/go.sum
#	processor/filterprocessor/go.mod
#	processor/filterprocessor/go.sum
#	processor/logdedupprocessor/go.mod
#	processor/logdedupprocessor/go.sum
#	processor/lookupprocessor/go.mod
#	processor/lookupprocessor/go.sum
#	processor/spanprocessor/go.mod
#	processor/spanprocessor/go.sum
#	processor/tailsamplingprocessor/go.mod
#	processor/tailsamplingprocessor/go.sum
#	processor/transformprocessor/go.mod
#	processor/transformprocessor/go.sum
Copy link
Copy Markdown
Contributor

@evan-bradley evan-bradley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ronkorland. Looks good to me.

Comment thread pkg/ottl/contexts/ottlotelcol/README.md
Comment thread pkg/ottl/contexts/internal/ctxotelcol/otelcol.go
Comment thread pkg/ottl/contexts/internal/ctxotelcol/otelcol.go Outdated
…etadata

- Added a reference URL for issue tracking related to the `otelcol` context.
- Specified the version from which the feature gate is available.
…simplifying code

- Removed several unused functions related to gRPC and client metadata accessors.
- Consolidated logic for converting string arrays to value slices.
- Improved code readability and maintainability by eliminating redundant error handling and comments.
Resolved go.mod/go.sum conflicts by taking main's versions; re-added collector/client in pkg/ottl for otelcol context.
@ronkorland
Copy link
Copy Markdown
Contributor Author

@evan-bradley I've addressed your feedback:
Feature Gate: Added the reference URL and version (v0.147.0).
Refactoring: Cleaned up the otelcol path handling and context logic.

@evan-bradley
Copy link
Copy Markdown
Contributor

Thanks @ronkorland. Looks good to me, just needs a make gotidy.

@ronkorland
Copy link
Copy Markdown
Contributor Author

Thanks @ronkorland. Looks good to me, just needs a make gotidy.

done

@otelbot
Copy link
Copy Markdown
Contributor

otelbot bot commented Feb 28, 2026

Thank you for your contribution @ronkorland! 🎉 We would like to hear from you about your experience contributing to OpenTelemetry by taking a few minutes to fill out this survey. If you are getting started contributing, you can also join the CNCF Slack channel #opentelemetry-new-contributors to ask for guidance and get help.

@evan-bradley
Copy link
Copy Markdown
Contributor

Saw again that this was opened in August of last year, just want to thank you again for being patient throughout the review process.

@edmocosta
Copy link
Copy Markdown
Contributor

Thank you @ronkorland for your great work and patience. I'm glad this feature finally landed :)

@ronkorland
Copy link
Copy Markdown
Contributor Author

Thank you @edmocosta and @evan-bradley for the thorough reviews and for sticking with this PR since August! I really appreciate the guidance on the feature gate implementation and the final refactoring.

I'm excited to see this land, and I'll be keeping an eye on the tracking issue for the feature gate moving forward. I'd be happy to jump back in for any further code changes or improvements needed, so please don't hesitate to reach out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[processor/transform] Set attribute values using connection context

10 participants