Skip to content

Commit b83e8e1

Browse files
authored
[pkg/ottl] Add event_name path to the OTTL Log context (#40311)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description This PR exposes the `event_name` path in Log OTTL context. Proto: https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/logs/v1/logs.proto#L224. <!-- Issue number (e.g. #1234) or full URL to issue, if applicable. --> #### Link to tracking issue Fixes #40230 <!--Describe what testing was performed and which tests were added.--> #### Testing Unit test <!--Describe the documentation added.--> #### Documentation README <!--Please delete paragraphs that you did not use before submitting.-->
1 parent a7b2119 commit b83e8e1

File tree

5 files changed

+56
-0
lines changed

5 files changed

+56
-0
lines changed
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: pkg/ottl
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Add `event_name` path to the OTTL Log context
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: [40230]
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/ctxlog/log.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ func PathGetSetter[K Context](path ottl.Path[K]) (ottl.GetSetter[K], error) {
7575
return nil, ctxerror.New(nextPath.Name(), path.String(), Name, DocRef)
7676
}
7777
return accessSpanID[K](), nil
78+
case "event_name":
79+
return accessEventName[K](), nil
7880
default:
7981
return nil, ctxerror.New(path.Name(), path.String(), Name, DocRef)
8082
}
@@ -331,3 +333,17 @@ func accessStringSpanID[K Context]() ottl.StandardGetSetter[K] {
331333
},
332334
}
333335
}
336+
337+
func accessEventName[K Context]() ottl.StandardGetSetter[K] {
338+
return ottl.StandardGetSetter[K]{
339+
Getter: func(_ context.Context, tCtx K) (any, error) {
340+
return tCtx.GetLogRecord().EventName(), nil
341+
},
342+
Setter: func(_ context.Context, tCtx K, val any) error {
343+
if v, ok := val.(string); ok {
344+
tCtx.GetLogRecord().SetEventName(v)
345+
}
346+
return nil
347+
},
348+
}
349+
}

pkg/ottl/contexts/internal/ctxlog/log_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,17 @@ func TestPathGetSetter(t *testing.T) {
342342
log.SetSpanID(spanID2)
343343
},
344344
},
345+
{
346+
name: "event_name",
347+
path: &pathtest.Path[*testContext]{
348+
N: "event_name",
349+
},
350+
orig: "",
351+
newVal: "exception",
352+
modified: func(log plog.LogRecord) {
353+
log.SetEventName("exception")
354+
},
355+
},
345356
}
346357
for _, tt := range tests {
347358
t.Run(tt.name, func(t *testing.T) {

pkg/ottl/contexts/ottllog/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ The following paths are supported.
2828
| instrumentation_scope.attributes\[""\] | the value of the instrumentation scope attribute of the data point being processed. Supports multiple indexes to access nested fields. | string, bool, int64, float64, pcommon.Map, pcommon.Slice, []byte or nil |
2929
| log.attributes | attributes of the log being processed | pcommon.Map |
3030
| log.attributes\[""\] | the value of the attribute of the log being processed. Supports multiple indexes to access nested fields. | string, bool, int64, float64, pcommon.Map, pcommon.Slice, []byte or nil |
31+
| log.event_name | the event name associated with the log being processed. | string |
3132
| log.trace_id | a byte slice representation of the trace id | pcommon.TraceID |
3233
| log.trace_id.string | a string representation of the trace id | string |
3334
| log.span_id | a byte slice representation of the span id | pcommon.SpanID |

pkg/ottl/contexts/ottllog/log.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ func (l logRecord) MarshalLogObject(encoder zapcore.ObjectEncoder) error {
5959
encoder.AddString("span_id", hex.EncodeToString(spanID[:]))
6060
encoder.AddUint64("time_unix_nano", uint64(lr.Timestamp()))
6161
encoder.AddString("trace_id", hex.EncodeToString(traceID[:]))
62+
encoder.AddString("event_name", lr.EventName())
6263
return err
6364
}
6465

0 commit comments

Comments
 (0)