Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
426762d
[pkg/ottl] Add client metadata access to OTTL contexts
Aug 10, 2025
ea6a092
Merge branch 'main' into metadata-context
Aug 12, 2025
1115d20
fix import into the right group
Aug 12, 2025
b8b2a2a
fix missing new collector/client dependency
Aug 12, 2025
42cdcc7
feat(ottl/context): add namespaced context paths; migrate metadata to…
Aug 14, 2025
8591ad6
fix lint errors + fix go.mod
Aug 14, 2025
e97d305
Merge branch 'main' into metadata-context
Aug 14, 2025
8b57e4e
fix lint
Aug 14, 2025
7d76b9f
Merge branch 'main' into metadata-context
Aug 15, 2025
a43ceb3
Merge branch 'main' into metadata-context
Aug 20, 2025
7193778
change return type to `pcommon.Slice` and `pcommon.Map` and change fu…
Aug 20, 2025
c163bdc
update docs + add `ottlcontext` + move `context` from parser to contexts
Aug 20, 2025
1f4539a
Merge branch 'main' into metadata-context
Aug 20, 2025
db6790b
Merge branch 'main' into metadata-context
Aug 22, 2025
b2a6240
fix gotidy after merge with main
Aug 22, 2025
3e1b8d3
fix lint
Aug 22, 2025
3810065
Merge branch 'main' into metadata-context
Aug 25, 2025
af0a75f
Merge branch 'main' into metadata-context
Aug 28, 2025
35a9a74
Merge branch 'main' into metadata-context
ronkorland Oct 3, 2025
6e7f6d8
make gotidy
ronkorland Oct 3, 2025
18c6ed3
CR fixes
ronkorland Oct 3, 2025
8931e8b
fix README files
ronkorland Oct 18, 2025
7d17bf9
Merge branch 'main' into metadata-context
ronkorland Oct 18, 2025
d0d7c8d
fix CR + tests
ronkorland Oct 18, 2025
2a57fd8
Merge branch 'main' into metadata-context
ronkorland Oct 27, 2025
5660a83
revert getIndexableValue
ronkorland Oct 27, 2025
2dee54e
CR
ronkorland Oct 27, 2025
4f74486
fix test and add ` around context.
ronkorland Oct 27, 2025
1a75ab8
fix lint error
ronkorland Oct 27, 2025
95cee5e
Merge branch 'main' into metadata-context
ronkorland Oct 31, 2025
f08006f
Update pkg/ottl/contexts/ottlcontext/README.md
ronkorland Oct 31, 2025
9004c08
remove comment
ronkorland Oct 31, 2025
c59813b
Merge branch 'metadata-context' of github.com:ronkorland/opentelemetr…
ronkorland Oct 31, 2025
381d7de
Update pkg/ottl/contexts/internal/ctxcontext/context_test.go
ronkorland Oct 31, 2025
4718508
Update pkg/ottl/contexts/internal/ctxcontext/context.go
ronkorland Oct 31, 2025
a0e9b49
Update pkg/ottl/contexts/internal/ctxcontext/context.go
ronkorland Oct 31, 2025
2b0cc37
Update pkg/ottl/contexts/internal/ctxcontext/context.go
ronkorland Oct 31, 2025
b3e64e7
Update pkg/ottl/contexts/internal/ctxcontext/context.go
ronkorland Oct 31, 2025
c28a73d
Merge branch 'metadata-context' of github.com:ronkorland/opentelemetr…
ronkorland Oct 31, 2025
0fd6a07
fix imports
ronkorland Oct 31, 2025
31c7c14
Merge branch 'main' into metadata-context
ronkorland Oct 31, 2025
c3ebf9a
Merge branch 'main' into metadata-context
ronkorland Nov 11, 2025
54956a1
Merge branch 'main' into metadata-context
ronkorland Nov 20, 2025
b3620fe
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
edmocosta Feb 12, 2026
d51ac0e
Renaming from `context` to `otelcol`
edmocosta Feb 12, 2026
0035ff0
Merge branch 'main' into metadata-context
edmocosta Feb 13, 2026
760e8d7
Go mod tidy
edmocosta Feb 13, 2026
9069073
make goporto
edmocosta Feb 13, 2026
2a15616
Update pkg/ottl/contexts/internal/ctxotelcol/otelcol_test.go
edmocosta Feb 13, 2026
71b93f3
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
edmocosta Feb 16, 2026
3685ffa
Change otelcol TransformContext to use pointer and update docs to inc…
edmocosta Feb 17, 2026
50be0be
Add otelcol feature gate
edmocosta Feb 17, 2026
cdeb370
Merge branch 'main' into metadata-context
edmocosta Feb 17, 2026
51767b6
make gotidy
edmocosta Feb 17, 2026
6ce11da
Merge branch 'main' into metadata-context
edmocosta Feb 17, 2026
2249f33
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
edmocosta Feb 17, 2026
aa6ff4b
make gotidy
edmocosta Feb 17, 2026
d12427f
Fix setter errors context name
edmocosta Feb 18, 2026
0cb2a84
Fix context name, comments and error format
edmocosta Feb 18, 2026
c2f96b4
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
edmocosta Feb 18, 2026
7834169
Enhance `otelcol` context feature gate registration with additional m…
ronkorland Feb 27, 2026
163b798
Refactor `otelcol` context handling by removing unused functions and …
ronkorland Feb 27, 2026
6a02fd5
fix commit
ronkorland Feb 27, 2026
fc2fc3d
Merge main into metadata-context
ronkorland Feb 27, 2026
1751526
run gotidy
ronkorland Feb 27, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .chloggen/33288-metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: pkg/ottl

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Added metadata access path to all OTTL contexts for accessing client request metadata

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [33288]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
1 change: 1 addition & 0 deletions connector/countconnector/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ require (
github.com/yusufpapurcu/wmi v1.2.4 // indirect
github.com/zeebo/xxh3 v1.1.0 // indirect
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
go.opentelemetry.io/collector/client v1.52.1-0.20260227062254-168030d61d7d // indirect
go.opentelemetry.io/collector/component/componentstatus v0.146.2-0.20260227062254-168030d61d7d // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.146.2-0.20260227062254-168030d61d7d // indirect
go.opentelemetry.io/collector/confmap/provider/envprovider v1.52.1-0.20260227062254-168030d61d7d // indirect
Expand Down
2 changes: 2 additions & 0 deletions connector/signaltometricsconnector/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ require (
github.com/ua-parser/uap-go v0.0.0-20240611065828-3a4781585db6 // indirect
github.com/zeebo/xxh3 v1.1.0 // indirect
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
go.opentelemetry.io/collector/client v1.52.1-0.20260227062254-168030d61d7d // indirect
go.opentelemetry.io/collector/consumer/xconsumer v0.146.2-0.20260227062254-168030d61d7d // indirect
go.opentelemetry.io/collector/featuregate v1.52.1-0.20260227062254-168030d61d7d // indirect
go.opentelemetry.io/collector/internal/componentalias v0.146.2-0.20260227062254-168030d61d7d // indirect
Expand All @@ -79,6 +80,7 @@ require (
golang.org/x/net v0.51.0 // indirect
golang.org/x/sys v0.41.0 // indirect
golang.org/x/text v0.34.0 // indirect
google.golang.org/grpc v1.79.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Expand Down
4 changes: 4 additions & 0 deletions connector/signaltometricsconnector/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions connector/sumconnector/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ require (
github.com/ua-parser/uap-go v0.0.0-20240611065828-3a4781585db6 // indirect
github.com/zeebo/xxh3 v1.1.0 // indirect
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
go.opentelemetry.io/collector/client v1.52.1-0.20260227062254-168030d61d7d // indirect
go.opentelemetry.io/collector/connector/xconnector v0.146.2-0.20260227062254-168030d61d7d // indirect
go.opentelemetry.io/collector/consumer/xconsumer v0.146.2-0.20260227062254-168030d61d7d // indirect
go.opentelemetry.io/collector/featuregate v1.52.1-0.20260227062254-168030d61d7d // indirect
Expand All @@ -77,6 +78,7 @@ require (
golang.org/x/net v0.51.0 // indirect
golang.org/x/sys v0.41.0 // indirect
golang.org/x/text v0.34.0 // indirect
google.golang.org/grpc v1.79.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Expand Down
4 changes: 4 additions & 0 deletions connector/sumconnector/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions internal/filter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ require (
github.com/ua-parser/uap-go v0.0.0-20240611065828-3a4781585db6 // indirect
github.com/zeebo/xxh3 v1.1.0 // indirect
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
go.opentelemetry.io/collector/client v1.52.1-0.20260227062254-168030d61d7d // indirect
go.opentelemetry.io/collector/pdata/pprofile v0.146.2-0.20260227062254-168030d61d7d // indirect
go.opentelemetry.io/otel/metric v1.40.0 // indirect
go.opentelemetry.io/otel/sdk v1.40.0 // indirect
Expand All @@ -63,6 +64,7 @@ require (
golang.org/x/net v0.51.0 // indirect
golang.org/x/sys v0.41.0 // indirect
golang.org/x/text v0.34.0 // indirect
google.golang.org/grpc v1.79.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Expand Down
6 changes: 6 additions & 0 deletions internal/filter/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

215 changes: 215 additions & 0 deletions pkg/ottl/contexts/internal/ctxotelcol/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package ctxotelcol // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxotelcol"

import (
"context"
"errors"
"fmt"

"go.opentelemetry.io/collector/client"
"go.opentelemetry.io/collector/pdata/pcommon"

"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxerror"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxutil"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/internal/ottlcommon"
)

func accessClient[K any](path ottl.Path[K]) (ottl.GetSetter[K], error) {
nextPath := path.Next()
if nextPath == nil {
return nil, ctxerror.New(path.Name(), path.String(), Name, DocRef)
}
switch nextPath.Name() {
case "addr":
return accessClientAddr(nextPath)
case "auth":
return accessClientAuth(nextPath)
case "metadata":
return accessClientMetadata(nextPath)
default:
return nil, ctxerror.New(nextPath.Name(), nextPath.String(), Name, DocRef)
}
}

func accessClientMetadata[K any](path ottl.Path[K]) (ottl.GetSetter[K], error) {
nextPath := path.Next()
if nextPath != nil {
return nil, ctxerror.New(nextPath.Name(), nextPath.String(), Name, DocRef)
}
if path.Keys() == nil {
return accessClientMetadataKeys[K](), nil
}
return accessClientMetadataKey[K](path.Keys()), nil
}

func accessClientAddr[K any](path ottl.Path[K]) (ottl.GetSetter[K], error) {
nextPath := path.Next()
if nextPath != nil {
return nil, ctxerror.New(nextPath.Name(), nextPath.String(), Name, DocRef)
}
if path.Keys() != nil {
return nil, ctxerror.New(path.Name(), path.String(), Name, DocRef)
}
return ottl.StandardGetSetter[K]{
Getter: func(ctx context.Context, _ K) (any, error) {
cl := client.FromContext(ctx)
if cl.Addr == nil {
return nil, nil
}
return cl.Addr.String(), nil
},
Setter: func(_ context.Context, _ K, _ any) error {
return fmt.Errorf(readOnlyPathErrMsg, "otelcol.client.addr")
},
}, nil
}

func getAuthAttributeValue(authData client.AuthData, key string) (pcommon.Value, error) {
attrVal := authData.GetAttribute(key)
switch typedAttrVal := attrVal.(type) {
case string:
return pcommon.NewValueStr(typedAttrVal), nil
case []string:
value := pcommon.NewValueSlice()
slice := value.Slice()
slice.EnsureCapacity(len(typedAttrVal))
for _, str := range typedAttrVal {
slice.AppendEmpty().SetStr(str)
}
return value, nil
default:
value := pcommon.NewValueEmpty()
err := value.FromRaw(attrVal)
if err != nil {
return pcommon.Value{}, err
}
return value, nil
}
}

func convertAuthDataToMap(authData client.AuthData) pcommon.Map {
authMap := pcommon.NewMap()
if authData == nil {
return authMap
}
names := authData.GetAttributeNames()
authMap.EnsureCapacity(len(names))
for _, name := range names {
newKeyValue := authMap.PutEmpty(name)
if value, err := getAuthAttributeValue(authData, name); err == nil {
value.MoveTo(newKeyValue)
}
}
return authMap
}

func accessClientAuth[K any](path ottl.Path[K]) (ottl.GetSetter[K], error) {
nextPath := path.Next()
if nextPath == nil {
return nil, ctxerror.New(path.Name(), path.String(), Name, DocRef)
}
switch nextPath.Name() {
case "attributes":
if nextPath.Keys() == nil {
return accessClientAuthAttributesKeys[K](), nil
}
return accessClientAuthAttributesKey[K](nextPath.Keys()), nil
default:
return nil, ctxerror.New(nextPath.Name(), nextPath.String(), Name, DocRef)
}
}

func accessClientAuthAttributesKeys[K any]() ottl.StandardGetSetter[K] {
return ottl.StandardGetSetter[K]{
Getter: func(ctx context.Context, _ K) (any, error) {
cl := client.FromContext(ctx)
return convertAuthDataToMap(cl.Auth), nil
},
Setter: func(_ context.Context, _ K, _ any) error {
return fmt.Errorf(readOnlyPathErrMsg, "otelcol.client.auth.attributes")
},
}
}

func accessClientAuthAttributesKey[K any](keys []ottl.Key[K]) ottl.StandardGetSetter[K] {
return ottl.StandardGetSetter[K]{
Getter: func(ctx context.Context, tCtx K) (any, error) {
if len(keys) == 0 {
return nil, errors.New("cannot get map value without keys")
}
cl := client.FromContext(ctx)
key, err := ctxutil.GetMapKeyName(ctx, tCtx, keys[0])
if err != nil {
return nil, err
}
if cl.Auth == nil {
return nil, nil
}
attrVal, err := getAuthAttributeValue(cl.Auth, *key)
if err != nil {
return nil, err
}
if len(keys) > 1 {
switch attrVal.Type() {
case pcommon.ValueTypeSlice:
return ctxutil.GetSliceValue[K](ctx, tCtx, attrVal.Slice(), keys[1:])
case pcommon.ValueTypeMap:
return ctxutil.GetMapValue[K](ctx, tCtx, attrVal.Map(), keys[1:])
default:
return nil, fmt.Errorf("attribute %q value is not indexable: %s", *key, attrVal.Type().String())
}
}
return ottlcommon.GetValue(attrVal), nil
},
Setter: func(_ context.Context, _ K, _ any) error {
return fmt.Errorf(readOnlyPathErrMsg, "otelcol.client.auth.attributes")
},
}
}

func convertClientMetadataToMap(md client.Metadata) pcommon.Map {
mdMap := pcommon.NewMap()
for k := range md.Keys() {
convertStringArrToValueSlice(md.Get(k)).MoveTo(mdMap.PutEmpty(k))
}
return mdMap
}

func accessClientMetadataKeys[K any]() ottl.StandardGetSetter[K] {
return ottl.StandardGetSetter[K]{
Getter: func(ctx context.Context, _ K) (any, error) {
cl := client.FromContext(ctx)
return convertClientMetadataToMap(cl.Metadata), nil
},
Setter: func(_ context.Context, _ K, _ any) error {
return fmt.Errorf(readOnlyPathErrMsg, "otelcol.client.metadata")
},
}
}

func accessClientMetadataKey[K any](keys []ottl.Key[K]) ottl.StandardGetSetter[K] {
return ottl.StandardGetSetter[K]{
Getter: func(ctx context.Context, tCtx K) (any, error) {
if len(keys) == 0 {
return nil, errors.New("cannot get map value without keys")
}

key, err := ctxutil.GetMapKeyName(ctx, tCtx, keys[0])
if err != nil {
return nil, fmt.Errorf("cannot get map value: %w", err)
}
cl := client.FromContext(ctx)
mdVal := cl.Metadata.Get(*key)
if len(mdVal) == 0 {
return nil, nil
}
return getIndexableValueFromStringArr(ctx, tCtx, keys[1:], mdVal)
},
Setter: func(_ context.Context, _ K, _ any) error {
return fmt.Errorf(readOnlyPathErrMsg, "otelcol.client.metadata")
},
}
}
10 changes: 10 additions & 0 deletions pkg/ottl/contexts/internal/ctxotelcol/context.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package ctxotelcol // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxotelcol"

const (
readOnlyPathErrMsg = "%q is read-only and cannot be modified"
Name = "otelcol"
DocRef = "https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/ottl/contexts/ottlotelcol"
)
Loading
Loading