@@ -88,9 +88,11 @@ func accessTimeUnixNano[K Context]() ottl.StandardGetSetter[K] {
8888 return tCtx .GetLogRecord ().Timestamp ().AsTime ().UnixNano (), nil
8989 },
9090 Setter : func (_ context.Context , tCtx K , val any ) error {
91- if i , ok := val .(int64 ); ok {
92- tCtx .GetLogRecord ().SetTimestamp (pcommon .NewTimestampFromTime (time .Unix (0 , i )))
91+ i , err := ctxutil.ExpectType [int64 ](val )
92+ if err != nil {
93+ return err
9394 }
95+ tCtx .GetLogRecord ().SetTimestamp (pcommon .NewTimestampFromTime (time .Unix (0 , i )))
9496 return nil
9597 },
9698 }
@@ -102,9 +104,11 @@ func accessObservedTimeUnixNano[K Context]() ottl.StandardGetSetter[K] {
102104 return tCtx .GetLogRecord ().ObservedTimestamp ().AsTime ().UnixNano (), nil
103105 },
104106 Setter : func (_ context.Context , tCtx K , val any ) error {
105- if i , ok := val .(int64 ); ok {
106- tCtx .GetLogRecord ().SetObservedTimestamp (pcommon .NewTimestampFromTime (time .Unix (0 , i )))
107+ i , err := ctxutil.ExpectType [int64 ](val )
108+ if err != nil {
109+ return err
107110 }
111+ tCtx .GetLogRecord ().SetObservedTimestamp (pcommon .NewTimestampFromTime (time .Unix (0 , i )))
108112 return nil
109113 },
110114 }
@@ -116,9 +120,11 @@ func accessTime[K Context]() ottl.StandardGetSetter[K] {
116120 return tCtx .GetLogRecord ().Timestamp ().AsTime (), nil
117121 },
118122 Setter : func (_ context.Context , tCtx K , val any ) error {
119- if i , ok := val .(time.Time ); ok {
120- tCtx .GetLogRecord ().SetTimestamp (pcommon .NewTimestampFromTime (i ))
123+ i , err := ctxutil.ExpectType [time.Time ](val )
124+ if err != nil {
125+ return err
121126 }
127+ tCtx .GetLogRecord ().SetTimestamp (pcommon .NewTimestampFromTime (i ))
122128 return nil
123129 },
124130 }
@@ -130,9 +136,11 @@ func accessObservedTime[K Context]() ottl.StandardGetSetter[K] {
130136 return tCtx .GetLogRecord ().ObservedTimestamp ().AsTime (), nil
131137 },
132138 Setter : func (_ context.Context , tCtx K , val any ) error {
133- if i , ok := val .(time.Time ); ok {
134- tCtx .GetLogRecord ().SetObservedTimestamp (pcommon .NewTimestampFromTime (i ))
139+ i , err := ctxutil.ExpectType [time.Time ](val )
140+ if err != nil {
141+ return err
135142 }
143+ tCtx .GetLogRecord ().SetObservedTimestamp (pcommon .NewTimestampFromTime (i ))
136144 return nil
137145 },
138146 }
@@ -144,9 +152,11 @@ func accessSeverityNumber[K Context]() ottl.StandardGetSetter[K] {
144152 return int64 (tCtx .GetLogRecord ().SeverityNumber ()), nil
145153 },
146154 Setter : func (_ context.Context , tCtx K , val any ) error {
147- if i , ok := val .(int64 ); ok {
148- tCtx .GetLogRecord ().SetSeverityNumber (plog .SeverityNumber (i ))
155+ i , err := ctxutil.ExpectType [int64 ](val )
156+ if err != nil {
157+ return err
149158 }
159+ tCtx .GetLogRecord ().SetSeverityNumber (plog .SeverityNumber (i ))
150160 return nil
151161 },
152162 }
@@ -158,9 +168,11 @@ func accessSeverityText[K Context]() ottl.StandardGetSetter[K] {
158168 return tCtx .GetLogRecord ().SeverityText (), nil
159169 },
160170 Setter : func (_ context.Context , tCtx K , val any ) error {
161- if s , ok := val .(string ); ok {
162- tCtx .GetLogRecord ().SetSeverityText (s )
171+ s , err := ctxutil.ExpectType [string ](val )
172+ if err != nil {
173+ return err
163174 }
175+ tCtx .GetLogRecord ().SetSeverityText (s )
164176 return nil
165177 },
166178 }
@@ -210,9 +222,11 @@ func accessStringBody[K Context]() ottl.StandardGetSetter[K] {
210222 return tCtx .GetLogRecord ().Body ().AsString (), nil
211223 },
212224 Setter : func (_ context.Context , tCtx K , val any ) error {
213- if str , ok := val .(string ); ok {
214- tCtx .GetLogRecord ().Body ().SetStr (str )
225+ str , err := ctxutil.ExpectType [string ](val )
226+ if err != nil {
227+ return err
215228 }
229+ tCtx .GetLogRecord ().Body ().SetStr (str )
216230 return nil
217231 },
218232 }
@@ -246,9 +260,11 @@ func accessDroppedAttributesCount[K Context]() ottl.StandardGetSetter[K] {
246260 return int64 (tCtx .GetLogRecord ().DroppedAttributesCount ()), nil
247261 },
248262 Setter : func (_ context.Context , tCtx K , val any ) error {
249- if i , ok := val .(int64 ); ok {
250- tCtx .GetLogRecord ().SetDroppedAttributesCount (uint32 (i ))
263+ i , err := ctxutil.ExpectType [int64 ](val )
264+ if err != nil {
265+ return err
251266 }
267+ tCtx .GetLogRecord ().SetDroppedAttributesCount (uint32 (i ))
252268 return nil
253269 },
254270 }
@@ -260,9 +276,11 @@ func accessFlags[K Context]() ottl.StandardGetSetter[K] {
260276 return int64 (tCtx .GetLogRecord ().Flags ()), nil
261277 },
262278 Setter : func (_ context.Context , tCtx K , val any ) error {
263- if i , ok := val .(int64 ); ok {
264- tCtx .GetLogRecord ().SetFlags (plog .LogRecordFlags (i ))
279+ i , err := ctxutil.ExpectType [int64 ](val )
280+ if err != nil {
281+ return err
265282 }
283+ tCtx .GetLogRecord ().SetFlags (plog .LogRecordFlags (i ))
266284 return nil
267285 },
268286 }
@@ -274,9 +292,11 @@ func accessTraceID[K Context]() ottl.StandardGetSetter[K] {
274292 return tCtx .GetLogRecord ().TraceID (), nil
275293 },
276294 Setter : func (_ context.Context , tCtx K , val any ) error {
277- if newTraceID , ok := val .(pcommon.TraceID ); ok {
278- tCtx .GetLogRecord ().SetTraceID (newTraceID )
295+ newTraceID , err := ctxutil.ExpectType [pcommon.TraceID ](val )
296+ if err != nil {
297+ return err
279298 }
299+ tCtx .GetLogRecord ().SetTraceID (newTraceID )
280300 return nil
281301 },
282302 }
@@ -289,13 +309,15 @@ func accessStringTraceID[K Context]() ottl.StandardGetSetter[K] {
289309 return hex .EncodeToString (id [:]), nil
290310 },
291311 Setter : func (_ context.Context , tCtx K , val any ) error {
292- if str , ok := val .(string ); ok {
293- id , err := ctxcommon .ParseTraceID (str )
294- if err != nil {
295- return err
296- }
297- tCtx .GetLogRecord ().SetTraceID (id )
312+ str , err := ctxutil.ExpectType [string ](val )
313+ if err != nil {
314+ return err
298315 }
316+ id , err := ctxcommon .ParseTraceID (str )
317+ if err != nil {
318+ return err
319+ }
320+ tCtx .GetLogRecord ().SetTraceID (id )
299321 return nil
300322 },
301323 }
@@ -307,9 +329,11 @@ func accessSpanID[K Context]() ottl.StandardGetSetter[K] {
307329 return tCtx .GetLogRecord ().SpanID (), nil
308330 },
309331 Setter : func (_ context.Context , tCtx K , val any ) error {
310- if newSpanID , ok := val .(pcommon.SpanID ); ok {
311- tCtx .GetLogRecord ().SetSpanID (newSpanID )
332+ newSpanID , err := ctxutil.ExpectType [pcommon.SpanID ](val )
333+ if err != nil {
334+ return err
312335 }
336+ tCtx .GetLogRecord ().SetSpanID (newSpanID )
313337 return nil
314338 },
315339 }
@@ -322,13 +346,15 @@ func accessStringSpanID[K Context]() ottl.StandardGetSetter[K] {
322346 return hex .EncodeToString (id [:]), nil
323347 },
324348 Setter : func (_ context.Context , tCtx K , val any ) error {
325- if str , ok := val .(string ); ok {
326- id , err := ctxcommon .ParseSpanID (str )
327- if err != nil {
328- return err
329- }
330- tCtx .GetLogRecord ().SetSpanID (id )
349+ str , err := ctxutil.ExpectType [string ](val )
350+ if err != nil {
351+ return err
352+ }
353+ id , err := ctxcommon .ParseSpanID (str )
354+ if err != nil {
355+ return err
331356 }
357+ tCtx .GetLogRecord ().SetSpanID (id )
332358 return nil
333359 },
334360 }
@@ -340,9 +366,11 @@ func accessEventName[K Context]() ottl.StandardGetSetter[K] {
340366 return tCtx .GetLogRecord ().EventName (), nil
341367 },
342368 Setter : func (_ context.Context , tCtx K , val any ) error {
343- if v , ok := val .(string ); ok {
344- tCtx .GetLogRecord ().SetEventName (v )
369+ v , err := ctxutil.ExpectType [string ](val )
370+ if err != nil {
371+ return err
345372 }
373+ tCtx .GetLogRecord ().SetEventName (v )
346374 return nil
347375 },
348376 }
0 commit comments