@@ -22,6 +22,7 @@ import (
22
22
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/logging"
23
23
)
24
24
25
+ // ContextName is the name of the context for logs.
25
26
// Experimental: *NOTE* this constant is subject to change or removal in the future.
26
27
const ContextName = ctxlog .Name
27
28
31
32
_ zapcore.ObjectMarshaler = (* TransformContext )(nil )
32
33
)
33
34
35
+ // TransformContext represents a log and its associated hierarchy.
34
36
type TransformContext struct {
35
37
logRecord plog.LogRecord
36
38
instrumentationScope pcommon.InstrumentationScope
@@ -42,6 +44,7 @@ type TransformContext struct {
42
44
43
45
type logRecord plog.LogRecord
44
46
47
+ // MarshalLogObject serializes the log into a zapcore.ObjectEncoder for logging.
45
48
func (l logRecord ) MarshalLogObject (encoder zapcore.ObjectEncoder ) error {
46
49
lr := plog .LogRecord (l )
47
50
spanID := lr .SpanID ()
@@ -59,6 +62,7 @@ func (l logRecord) MarshalLogObject(encoder zapcore.ObjectEncoder) error {
59
62
return err
60
63
}
61
64
65
+ // MarshalLogObject serializes the TransformContext into a zapcore.ObjectEncoder for logging.
62
66
func (tCtx TransformContext ) MarshalLogObject (encoder zapcore.ObjectEncoder ) error {
63
67
err := encoder .AddObject ("resource" , logging .Resource (tCtx .resource ))
64
68
err = errors .Join (err , encoder .AddObject ("scope" , logging .InstrumentationScope (tCtx .instrumentationScope )))
@@ -67,8 +71,10 @@ func (tCtx TransformContext) MarshalLogObject(encoder zapcore.ObjectEncoder) err
67
71
return err
68
72
}
69
73
74
+ // TransformContextOption represents an option for configuring a TransformContext.
70
75
type TransformContextOption func (* TransformContext )
71
76
77
+ // NewTransformContext creates a new TransformContext with the provided parameters.
72
78
func NewTransformContext (logRecord plog.LogRecord , instrumentationScope pcommon.InstrumentationScope , resource pcommon.Resource , scopeLogs plog.ScopeLogs , resourceLogs plog.ResourceLogs , options ... TransformContextOption ) TransformContext {
73
79
tc := TransformContext {
74
80
logRecord : logRecord ,
@@ -84,27 +90,32 @@ func NewTransformContext(logRecord plog.LogRecord, instrumentationScope pcommon.
84
90
return tc
85
91
}
86
92
93
+ // GetLogRecord returns the log record from the TransformContext.
87
94
func (tCtx TransformContext ) GetLogRecord () plog.LogRecord {
88
95
return tCtx .logRecord
89
96
}
90
97
98
+ // GetInstrumentationScope returns the instrumentation scope from the TransformContext.
91
99
func (tCtx TransformContext ) GetInstrumentationScope () pcommon.InstrumentationScope {
92
100
return tCtx .instrumentationScope
93
101
}
94
102
103
+ // GetResource returns the resource from the TransformContext.
95
104
func (tCtx TransformContext ) GetResource () pcommon.Resource {
96
105
return tCtx .resource
97
106
}
98
107
108
+ // GetScopeSchemaURLItem returns the scope schema URL item from the TransformContext.
99
109
func (tCtx TransformContext ) GetScopeSchemaURLItem () ctxcommon.SchemaURLItem {
100
110
return tCtx .scopeLogs
101
111
}
102
112
113
+ // GetResourceSchemaURLItem returns the resource schema URL item from the TransformContext.
103
114
func (tCtx TransformContext ) GetResourceSchemaURLItem () ctxcommon.SchemaURLItem {
104
115
return tCtx .resourceLogs
105
116
}
106
117
107
- // EnablePathContextNames enables the support to path's context names on statements.
118
+ // EnablePathContextNames enables the support for path's context names on statements.
108
119
// When this option is configured, all statement's paths must have a valid context prefix,
109
120
// otherwise an error is reported.
110
121
//
@@ -119,14 +130,17 @@ func EnablePathContextNames() ottl.Option[TransformContext] {
119
130
}
120
131
}
121
132
133
+ // StatementSequenceOption represents an option for configuring a statement sequence.
122
134
type StatementSequenceOption func (* ottl.StatementSequence [TransformContext ])
123
135
136
+ // WithStatementSequenceErrorMode sets the error mode for a statement sequence.
124
137
func WithStatementSequenceErrorMode (errorMode ottl.ErrorMode ) StatementSequenceOption {
125
138
return func (s * ottl.StatementSequence [TransformContext ]) {
126
139
ottl.WithStatementSequenceErrorMode [TransformContext ](errorMode )(s )
127
140
}
128
141
}
129
142
143
+ // NewStatementSequence creates a new statement sequence with the provided statements and options.
130
144
func NewStatementSequence (statements []* ottl.Statement [TransformContext ], telemetrySettings component.TelemetrySettings , options ... StatementSequenceOption ) ottl.StatementSequence [TransformContext ] {
131
145
s := ottl .NewStatementSequence (statements , telemetrySettings )
132
146
for _ , op := range options {
@@ -135,14 +149,17 @@ func NewStatementSequence(statements []*ottl.Statement[TransformContext], teleme
135
149
return s
136
150
}
137
151
152
+ // ConditionSequenceOption represents an option for configuring a condition sequence.
138
153
type ConditionSequenceOption func (* ottl.ConditionSequence [TransformContext ])
139
154
155
+ // WithConditionSequenceErrorMode sets the error mode for a condition sequence.
140
156
func WithConditionSequenceErrorMode (errorMode ottl.ErrorMode ) ConditionSequenceOption {
141
157
return func (c * ottl.ConditionSequence [TransformContext ]) {
142
158
ottl.WithConditionSequenceErrorMode [TransformContext ](errorMode )(c )
143
159
}
144
160
}
145
161
162
+ // NewConditionSequence creates a new condition sequence with the provided conditions and options.
146
163
func NewConditionSequence (conditions []* ottl.Condition [TransformContext ], telemetrySettings component.TelemetrySettings , options ... ConditionSequenceOption ) ottl.ConditionSequence [TransformContext ] {
147
164
c := ottl .NewConditionSequence (conditions , telemetrySettings )
148
165
for _ , op := range options {
@@ -151,6 +168,7 @@ func NewConditionSequence(conditions []*ottl.Condition[TransformContext], teleme
151
168
return c
152
169
}
153
170
171
+ // NewParser creates a new log parser with the provided functions and options.
154
172
func NewParser (
155
173
functions map [string ]ottl.Factory [TransformContext ],
156
174
telemetrySettings component.TelemetrySettings ,
0 commit comments