Skip to content

Commit 32bd950

Browse files
rockdabootFiery-Fenix
authored andcommitted
[pkg/ottl] Add OTTL support for profiles (open-telemetry#37574)
Fixes open-telemetry#36104 This is a first PR to get profiles support into OTTL. Follow-up PRs will add support for more sub-types of profiles like `sample`, `mapping` etc..
1 parent fb91ea5 commit 32bd950

File tree

14 files changed

+1877
-0
lines changed

14 files changed

+1877
-0
lines changed

.chloggen/ottl-profile.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: ottlprofile
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Add OTTL support for profiles.
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [36104]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: []

pkg/ottl/contexts/internal/ctxcommon/ids.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"errors"
99

1010
"go.opentelemetry.io/collector/pdata/pcommon"
11+
"go.opentelemetry.io/collector/pdata/pprofile"
1112
)
1213

1314
func ParseSpanID(spanIDStr string) (pcommon.SpanID, error) {
@@ -33,3 +34,15 @@ func ParseTraceID(traceIDStr string) (pcommon.TraceID, error) {
3334
}
3435
return id, nil
3536
}
37+
38+
func ParseProfileID(profileIDStr string) (pprofile.ProfileID, error) {
39+
var id pprofile.ProfileID
40+
if hex.DecodedLen(len(profileIDStr)) != len(id) {
41+
return pprofile.ProfileID{}, errors.New("profile ids must be 32 hex characters")
42+
}
43+
_, err := hex.Decode(id[:], []byte(profileIDStr))
44+
if err != nil {
45+
return pprofile.ProfileID{}, err
46+
}
47+
return id, nil
48+
}

pkg/ottl/contexts/internal/ctxcommon/ids_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,28 @@ func TestParseTraceIDError(t *testing.T) {
6060
})
6161
}
6262
}
63+
64+
func TestParseProfileIDError(t *testing.T) {
65+
tests := []struct {
66+
name string
67+
input string
68+
wantErr string
69+
}{
70+
{
71+
name: "incorrect size",
72+
input: "0123456789abcdef0123456789abcde",
73+
wantErr: "profile ids must be 32 hex characters",
74+
},
75+
{
76+
name: "incorrect characters",
77+
input: "0123456789Xbcdef0123456789abcdef",
78+
wantErr: "encoding/hex: invalid byte: U+0058 'X'",
79+
},
80+
}
81+
for _, tt := range tests {
82+
t.Run(tt.name, func(t *testing.T) {
83+
_, err := ctxcommon.ParseProfileID(tt.input)
84+
assert.EqualError(t, err, tt.wantErr)
85+
})
86+
}
87+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package ctxprofile // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxprofile"
5+
import (
6+
"go.opentelemetry.io/collector/pdata/pprofile"
7+
)
8+
9+
const (
10+
Name = "profile"
11+
DocRef = "https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/ottl/contexts/ottlprofile"
12+
)
13+
14+
type Context interface {
15+
GetProfile() pprofile.Profile
16+
}

0 commit comments

Comments
 (0)