diff --git a/pkg/ottl/contexts/internal/resource.go b/pkg/ottl/contexts/internal/resource.go
index 2dfee7fce9f8..58f516dfe0e6 100644
--- a/pkg/ottl/contexts/internal/resource.go
+++ b/pkg/ottl/contexts/internal/resource.go
@@ -71,6 +71,7 @@ func accessResourceAttributesKey[K ResourceContext](keys []ottl.Key[K]) ottl.Sta
Setter: func(ctx context.Context, tCtx K, val any) error {
return SetMapValue[K](ctx, tCtx, tCtx.GetResource().Attributes(), keys, val)
},
+ // TODO
}
}
diff --git a/pkg/ottl/contexts/internal/scope.go b/pkg/ottl/contexts/internal/scope.go
index 6bc5d7352005..13b473a71df6 100644
--- a/pkg/ottl/contexts/internal/scope.go
+++ b/pkg/ottl/contexts/internal/scope.go
@@ -76,6 +76,7 @@ func accessInstrumentationScopeAttributesKey[K InstrumentationScopeContext](keys
Setter: func(ctx context.Context, tCtx K, val any) error {
return SetMapValue[K](ctx, tCtx, tCtx.GetInstrumentationScope().Attributes(), keys, val)
},
+ // TODO
}
}
diff --git a/pkg/ottl/contexts/internal/span.go b/pkg/ottl/contexts/internal/span.go
index 607cb2e110f9..855ca8d5c5de 100644
--- a/pkg/ottl/contexts/internal/span.go
+++ b/pkg/ottl/contexts/internal/span.go
@@ -465,6 +465,7 @@ func accessAttributesKey[K SpanContext](keys []ottl.Key[K]) ottl.StandardGetSett
Setter: func(ctx context.Context, tCtx K, val any) error {
return SetMapValue[K](ctx, tCtx, tCtx.GetSpan().Attributes(), keys, val)
},
+ // TODO
}
}
diff --git a/pkg/ottl/contexts/ottldatapoint/datapoint.go b/pkg/ottl/contexts/ottldatapoint/datapoint.go
index 9c50d85cd723..fc5e8170a557 100644
--- a/pkg/ottl/contexts/ottldatapoint/datapoint.go
+++ b/pkg/ottl/contexts/ottldatapoint/datapoint.go
@@ -353,6 +353,7 @@ func accessAttributesKey(key []ottl.Key[TransformContext]) ottl.StandardGetSette
case pmetric.SummaryDataPoint:
return internal.SetMapValue[TransformContext](ctx, tCtx, tCtx.GetDataPoint().(pmetric.SummaryDataPoint).Attributes(), key, val)
}
+ // TODO
return nil
},
}
diff --git a/pkg/ottl/contexts/ottllog/log.go b/pkg/ottl/contexts/ottllog/log.go
index 7ca056730cc7..3dde1bb851e6 100644
--- a/pkg/ottl/contexts/ottllog/log.go
+++ b/pkg/ottl/contexts/ottllog/log.go
@@ -448,6 +448,7 @@ func accessAttributesKey(key []ottl.Key[TransformContext]) ottl.StandardGetSette
Setter: func(ctx context.Context, tCtx TransformContext, val any) error {
return internal.SetMapValue[TransformContext](ctx, tCtx, tCtx.GetLogRecord().Attributes(), key, val)
},
+ // TODO
}
}
diff --git a/pkg/ottl/contexts/ottlspanevent/span_events.go b/pkg/ottl/contexts/ottlspanevent/span_events.go
index b3826f690d2d..7e8851ec1033 100644
--- a/pkg/ottl/contexts/ottlspanevent/span_events.go
+++ b/pkg/ottl/contexts/ottlspanevent/span_events.go
@@ -272,6 +272,7 @@ func accessSpanEventAttributesKey(key []ottl.Key[TransformContext]) ottl.Standar
Setter: func(ctx context.Context, tCtx TransformContext, val any) error {
return internal.SetMapValue[TransformContext](ctx, tCtx, tCtx.GetSpanEvent().Attributes(), key, val)
},
+ // TODO
}
}
diff --git a/pkg/ottl/e2e/e2e_test.go b/pkg/ottl/e2e/e2e_test.go
index bb1dd43b5282..77c948211784 100644
--- a/pkg/ottl/e2e/e2e_test.go
+++ b/pkg/ottl/e2e/e2e_test.go
@@ -5,11 +5,11 @@ package e2e
import (
"context"
- "net/http"
"testing"
"time"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/plog"
@@ -330,635 +330,635 @@ func Test_e2e_converters(t *testing.T) {
want func(tCtx ottllog.TransformContext)
}{
{
- statement: `set(attributes["test"], Base64Decode("cGFzcw=="))`,
+ statement: `set(${attributes["test"]}, Base64Decode("cGFzcw=="))`,
want: func(tCtx ottllog.TransformContext) {
tCtx.GetLogRecord().Attributes().PutStr("test", "pass")
},
},
- {
- statement: `set(attributes["test"], Decode("cGFzcw==", "base64"))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", "pass")
- },
- },
- {
- statement: `set(attributes["test"], Concat(["A","B"], ":"))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", "A:B")
- },
- },
- {
- statement: `set(attributes["test"], ConvertCase(attributes["http.method"], "upper"))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", http.MethodGet)
- },
- },
- {
- statement: `set(attributes["test"], ConvertCase("PASS", "lower"))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", "pass")
- },
- },
- {
- statement: `set(attributes["test"], ConvertCase("fooBar", "snake"))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", "foo_bar")
- },
- },
- {
- statement: `set(attributes["test"], ConvertCase("foo_bar", "camel"))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", "FooBar")
- },
- },
- {
- statement: `set(attributes["test"], ConvertAttributesToElementsXML("This is a log message!"))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", `This is a log message!1`)
- },
- },
- {
- statement: `set(body, ConvertTextToElementsXML("foo"))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Body().SetStr("foo")
- },
- },
- {
- statement: `set(body, ConvertTextToElementsXML("foobar", "/a", "custom"))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Body().SetStr("foobar")
- },
- },
- {
- statement: `set(attributes["test"], Double(1.0))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutDouble("test", 1.0)
- },
- },
- {
- statement: `set(attributes["test"], Double("1"))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutDouble("test", 1.0)
- },
- },
- {
- statement: `set(attributes["test"], Double(true))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutDouble("test", 1.0)
- },
- },
- {
- statement: `set(attributes["test"], Double(1))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutDouble("test", 1.0)
- },
- },
- {
- statement: `set(attributes["test"], "pass") where Time("10", "%M") - Time("01", "%M") < Duration("10m")`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", "pass")
- },
- },
- {
- statement: `set(attributes["test"], ExtractPatterns("aa123bb", "(?P\\d+)"))`,
- want: func(tCtx ottllog.TransformContext) {
- m := tCtx.GetLogRecord().Attributes().PutEmptyMap("test")
- m.PutStr("numbers", "123")
- },
- },
- {
- statement: `set(attributes["test"], ExtractGrokPatterns("http://user:password@example.com:80/path?query=string", "%{ELB_URI}", true))`,
- want: func(tCtx ottllog.TransformContext) {
- m := tCtx.GetLogRecord().Attributes().PutEmptyMap("test")
- m.PutStr("url.scheme", "http")
- m.PutStr("url.username", "user")
- m.PutStr("url.domain", "example.com")
- m.PutInt("url.port", 80)
- m.PutStr("url.path", "/path")
- m.PutStr("url.query", "query=string")
- },
- },
- {
- statement: `set(attributes["test"], FNV("pass"))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutInt("test", 266877920130663416)
- },
- },
- {
- statement: `set(attributes["test"], Format("%03d-%s", [7, "test"]))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", "007-test")
- },
- },
- {
- statement: `set(attributes["test"], Hour(Time("12", "%H")))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutInt("test", 12)
- },
- },
- {
- statement: `set(attributes["test"], Hours(Duration("90m")))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutDouble("test", 1.5)
- },
- },
- {
- statement: `set(attributes["test"], InsertXML("", "/a", ""))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", "")
- },
- },
- {
- statement: `set(attributes["test"], Int(1.0))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutInt("test", 1)
- },
- },
- {
- statement: `set(attributes["test"], Int("1"))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutInt("test", 1)
- },
- },
- {
- statement: `set(attributes["test"], Int(true))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutInt("test", 1)
- },
- },
- {
- statement: `set(attributes["test"], Int(1))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutInt("test", 1)
- },
- },
- {
- statement: `set(attributes["test"], GetXML("12", "/a//b"))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", "12")
- },
- },
- {
- statement: `set(attributes["test"], Hex(1.0))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", "3ff0000000000000")
- },
- },
- {
- statement: `set(attributes["test"], Hex(true))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", "01")
- },
- },
- {
- statement: `set(attributes["test"], Hex(12))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", "000000000000000c")
- },
- },
- {
- statement: `set(attributes["test"], Hex("12"))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", "3132")
- },
- },
- {
- statement: `set(attributes["test"], "pass") where IsBool(false)`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", "pass")
- },
- },
- {
- statement: `set(attributes["test"], "pass") where IsDouble(1.0)`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", "pass")
- },
- },
- {
- statement: `set(attributes["test"], "pass") where IsMap(attributes["foo"])`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", "pass")
- },
- },
- {
- statement: `set(attributes["test"], "pass") where IsList(attributes["foo"]["slice"])`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", "pass")
- },
- },
- {
- statement: `set(attributes["test"], "pass") where IsMatch("aa123bb", "\\d{3}")`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", "pass")
- },
- },
- {
- statement: `set(attributes["test"], "pass") where IsString("")`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", "pass")
- },
- },
- {
- statement: `set(attributes["test"], Len(attributes["foo"]))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutInt("test", 4)
- },
- },
- {
- statement: `set(attributes["test"], Log(1))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutDouble("test", 0)
- },
- },
- {
- statement: `set(attributes["test"], MD5("pass"))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", "1a1dc91c907325c69271ddf0c944bc72")
- },
- },
- {
- statement: `set(attributes["test"], Microseconds(Duration("1ms")))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutInt("test", 1000)
- },
- },
- {
- statement: `set(attributes["test"], Milliseconds(Duration("1s")))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutInt("test", 1000)
- },
- },
- {
- statement: `set(attributes["test"], Minutes(Duration("1h")))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutDouble("test", 60)
- },
- },
- {
- statement: `set(attributes["test"], Nanoseconds(Duration("1ms")))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutInt("test", 1000000)
- },
- },
- {
- statement: `set(attributes["test"], "pass") where Now() - Now() < Duration("1h")`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", "pass")
- },
- },
- {
- statement: `set(attributes["test"], ParseCSV("val1;val2;val3","header1|header2|header3",";","|","strict"))`,
- want: func(tCtx ottllog.TransformContext) {
- m := tCtx.GetLogRecord().Attributes().PutEmptyMap("test")
- m.PutStr("header1", "val1")
- m.PutStr("header2", "val2")
- m.PutStr("header3", "val3")
- },
- },
- {
- statement: `set(attributes["test"], ParseCSV("val1,val2,val3","header1|header2|header3",headerDelimiter="|",mode="strict"))`,
- want: func(tCtx ottllog.TransformContext) {
- m := tCtx.GetLogRecord().Attributes().PutEmptyMap("test")
- m.PutStr("header1", "val1")
- m.PutStr("header2", "val2")
- m.PutStr("header3", "val3")
- },
- },
- {
- statement: `set(attributes["test"], ParseJSON("{\"id\":1}"))`,
- want: func(tCtx ottllog.TransformContext) {
- m := tCtx.GetLogRecord().Attributes().PutEmptyMap("test")
- m.PutDouble("id", 1)
- },
- },
- {
- statement: `set(attributes["test"], ParseJSON("[\"value1\",\"value2\"]"))`,
- want: func(tCtx ottllog.TransformContext) {
- m := tCtx.GetLogRecord().Attributes().PutEmptySlice("test")
- m.AppendEmpty().SetStr("value1")
- m.AppendEmpty().SetStr("value2")
- },
- },
- {
- statement: `set(attributes["test"], ParseKeyValue("k1=v1 k2=v2"))`,
- want: func(tCtx ottllog.TransformContext) {
- m := tCtx.GetLogRecord().Attributes().PutEmptyMap("test")
- m.PutStr("k1", "v1")
- m.PutStr("k2", "v2")
- },
- },
- {
- statement: `set(attributes["test"], ParseKeyValue("k1!v1_k2!v2", "!", "_"))`,
- want: func(tCtx ottllog.TransformContext) {
- m := tCtx.GetLogRecord().Attributes().PutEmptyMap("test")
- m.PutStr("k1", "v1")
- m.PutStr("k2", "v2")
- },
- },
- {
- statement: `set(attributes["test"], ParseKeyValue("k1!v1_k2!\"v2__!__v2\"", "!", "_"))`,
- want: func(tCtx ottllog.TransformContext) {
- m := tCtx.GetLogRecord().Attributes().PutEmptyMap("test")
- m.PutStr("k1", "v1")
- m.PutStr("k2", "v2__!__v2")
- },
- },
- {
- statement: `set(attributes["test"], ToKeyValueString(ParseKeyValue("k1=v1 k2=v2"), "=", " ", true))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", "k1=v1 k2=v2")
- },
- },
- {
- statement: `set(attributes["test"], ToKeyValueString(ParseKeyValue("k1:v1,k2:v2", ":" , ","), ":", ",", true))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", "k1:v1,k2:v2")
- },
- },
- {
- statement: `set(attributes["test"], ToKeyValueString(ParseKeyValue("k1=v1 k2=v2"), "!", "+", true))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", "k1!v1+k2!v2")
- },
- },
- {
- statement: `set(attributes["test"], ToKeyValueString(ParseKeyValue("k1=v1 k2=v2=v3"), "=", " ", true))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", "k1=v1 k2=\"v2=v3\"")
- },
- },
- {
- statement: `set(attributes["test"], ParseSimplifiedXML("1This is a log message!"))`,
- want: func(tCtx ottllog.TransformContext) {
- attr := tCtx.GetLogRecord().Attributes().PutEmptyMap("test")
- log := attr.PutEmptyMap("Log")
- log.PutStr("id", "1")
- log.PutStr("Message", "This is a log message!")
- },
- },
- {
- statement: `set(attributes["test"], ParseXML("This is a log message!"))`,
- want: func(tCtx ottllog.TransformContext) {
- log := tCtx.GetLogRecord().Attributes().PutEmptyMap("test")
- log.PutStr("tag", "Log")
+ // {
+ // statement: `set(attributes["test"], Decode("cGFzcw==", "base64"))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", "pass")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], Concat(["A","B"], ":"))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", "A:B")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], ConvertCase(attributes["http.method"], "upper"))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", http.MethodGet)
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], ConvertCase("PASS", "lower"))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", "pass")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], ConvertCase("fooBar", "snake"))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", "foo_bar")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], ConvertCase("foo_bar", "camel"))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", "FooBar")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], ConvertAttributesToElementsXML("This is a log message!"))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", `This is a log message!1`)
+ // },
+ // },
+ // {
+ // statement: `set(body, ConvertTextToElementsXML("foo"))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Body().SetStr("foo")
+ // },
+ // },
+ // {
+ // statement: `set(body, ConvertTextToElementsXML("foobar", "/a", "custom"))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Body().SetStr("foobar")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], Double(1.0))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutDouble("test", 1.0)
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], Double("1"))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutDouble("test", 1.0)
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], Double(true))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutDouble("test", 1.0)
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], Double(1))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutDouble("test", 1.0)
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], "pass") where Time("10", "%M") - Time("01", "%M") < Duration("10m")`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", "pass")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], ExtractPatterns("aa123bb", "(?P\\d+)"))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // m := tCtx.GetLogRecord().Attributes().PutEmptyMap("test")
+ // m.PutStr("numbers", "123")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], ExtractGrokPatterns("http://user:password@example.com:80/path?query=string", "%{ELB_URI}", true))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // m := tCtx.GetLogRecord().Attributes().PutEmptyMap("test")
+ // m.PutStr("url.scheme", "http")
+ // m.PutStr("url.username", "user")
+ // m.PutStr("url.domain", "example.com")
+ // m.PutInt("url.port", 80)
+ // m.PutStr("url.path", "/path")
+ // m.PutStr("url.query", "query=string")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], FNV("pass"))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutInt("test", 266877920130663416)
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], Format("%03d-%s", [7, "test"]))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", "007-test")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], Hour(Time("12", "%H")))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutInt("test", 12)
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], Hours(Duration("90m")))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutDouble("test", 1.5)
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], InsertXML("", "/a", ""))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", "")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], Int(1.0))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutInt("test", 1)
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], Int("1"))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutInt("test", 1)
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], Int(true))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutInt("test", 1)
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], Int(1))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutInt("test", 1)
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], GetXML("12", "/a//b"))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", "12")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], Hex(1.0))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", "3ff0000000000000")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], Hex(true))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", "01")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], Hex(12))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", "000000000000000c")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], Hex("12"))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", "3132")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], "pass") where IsBool(false)`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", "pass")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], "pass") where IsDouble(1.0)`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", "pass")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], "pass") where IsMap(attributes["foo"])`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", "pass")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], "pass") where IsList(attributes["foo"]["slice"])`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", "pass")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], "pass") where IsMatch("aa123bb", "\\d{3}")`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", "pass")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], "pass") where IsString("")`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", "pass")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], Len(attributes["foo"]))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutInt("test", 4)
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], Log(1))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutDouble("test", 0)
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], MD5("pass"))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", "1a1dc91c907325c69271ddf0c944bc72")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], Microseconds(Duration("1ms")))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutInt("test", 1000)
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], Milliseconds(Duration("1s")))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutInt("test", 1000)
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], Minutes(Duration("1h")))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutDouble("test", 60)
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], Nanoseconds(Duration("1ms")))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutInt("test", 1000000)
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], "pass") where Now() - Now() < Duration("1h")`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", "pass")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], ParseCSV("val1;val2;val3","header1|header2|header3",";","|","strict"))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // m := tCtx.GetLogRecord().Attributes().PutEmptyMap("test")
+ // m.PutStr("header1", "val1")
+ // m.PutStr("header2", "val2")
+ // m.PutStr("header3", "val3")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], ParseCSV("val1,val2,val3","header1|header2|header3",headerDelimiter="|",mode="strict"))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // m := tCtx.GetLogRecord().Attributes().PutEmptyMap("test")
+ // m.PutStr("header1", "val1")
+ // m.PutStr("header2", "val2")
+ // m.PutStr("header3", "val3")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], ParseJSON("{\"id\":1}"))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // m := tCtx.GetLogRecord().Attributes().PutEmptyMap("test")
+ // m.PutDouble("id", 1)
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], ParseJSON("[\"value1\",\"value2\"]"))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // m := tCtx.GetLogRecord().Attributes().PutEmptySlice("test")
+ // m.AppendEmpty().SetStr("value1")
+ // m.AppendEmpty().SetStr("value2")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], ParseKeyValue("k1=v1 k2=v2"))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // m := tCtx.GetLogRecord().Attributes().PutEmptyMap("test")
+ // m.PutStr("k1", "v1")
+ // m.PutStr("k2", "v2")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], ParseKeyValue("k1!v1_k2!v2", "!", "_"))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // m := tCtx.GetLogRecord().Attributes().PutEmptyMap("test")
+ // m.PutStr("k1", "v1")
+ // m.PutStr("k2", "v2")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], ParseKeyValue("k1!v1_k2!\"v2__!__v2\"", "!", "_"))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // m := tCtx.GetLogRecord().Attributes().PutEmptyMap("test")
+ // m.PutStr("k1", "v1")
+ // m.PutStr("k2", "v2__!__v2")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], ToKeyValueString(ParseKeyValue("k1=v1 k2=v2"), "=", " ", true))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", "k1=v1 k2=v2")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], ToKeyValueString(ParseKeyValue("k1:v1,k2:v2", ":" , ","), ":", ",", true))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", "k1:v1,k2:v2")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], ToKeyValueString(ParseKeyValue("k1=v1 k2=v2"), "!", "+", true))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", "k1!v1+k2!v2")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], ToKeyValueString(ParseKeyValue("k1=v1 k2=v2=v3"), "=", " ", true))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", "k1=v1 k2=\"v2=v3\"")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], ParseSimplifiedXML("1This is a log message!"))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // attr := tCtx.GetLogRecord().Attributes().PutEmptyMap("test")
+ // log := attr.PutEmptyMap("Log")
+ // log.PutStr("id", "1")
+ // log.PutStr("Message", "This is a log message!")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], ParseXML("This is a log message!"))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // log := tCtx.GetLogRecord().Attributes().PutEmptyMap("test")
+ // log.PutStr("tag", "Log")
- attrs := log.PutEmptyMap("attributes")
- attrs.PutStr("id", "1")
+ // attrs := log.PutEmptyMap("attributes")
+ // attrs.PutStr("id", "1")
- logChildren := log.PutEmptySlice("children")
+ // logChildren := log.PutEmptySlice("children")
- message := logChildren.AppendEmpty().SetEmptyMap()
- message.PutStr("tag", "Message")
- message.PutStr("content", "This is a log message!")
- },
- },
- {
- statement: `set(attributes["test"], RemoveXML("This is a log message!", "/Log/Message"))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", ``)
- },
- },
- {
- statement: `set(attributes["test"], Seconds(Duration("1m")))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutDouble("test", 60)
- },
- },
- {
- statement: `set(attributes["test"], SHA1("pass"))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", "9d4e1e23bd5b727046a9e3b4b7db57bd8d6ee684")
- },
- },
- {
- statement: `set(attributes["test"], SHA256("pass"))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", "d74ff0ee8da3b9806b18c877dbf29bbde50b5bd8e4dad7a3a725000feb82e8f1")
- },
- },
- {
- statement: `set(attributes["test"], SHA512("pass"))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", "5b722b307fce6c944905d132691d5e4a2214b7fe92b738920eb3fce3a90420a19511c3010a0e7712b054daef5b57bad59ecbd93b3280f210578f547f4aed4d25")
- },
- },
- {
- statement: `set(attributes["test"], Sort(Split(attributes["flags"], "|"), "desc"))`,
- want: func(tCtx ottllog.TransformContext) {
- s := tCtx.GetLogRecord().Attributes().PutEmptySlice("test")
- s.AppendEmpty().SetStr("C")
- s.AppendEmpty().SetStr("B")
- s.AppendEmpty().SetStr("A")
- },
- },
- {
- statement: `set(attributes["test"], Sort([true, false, false]))`,
- want: func(tCtx ottllog.TransformContext) {
- s := tCtx.GetLogRecord().Attributes().PutEmptySlice("test")
- s.AppendEmpty().SetBool(false)
- s.AppendEmpty().SetBool(false)
- s.AppendEmpty().SetBool(true)
- },
- },
- {
- statement: `set(attributes["test"], Sort([3, 6, 9], "desc"))`,
- want: func(tCtx ottllog.TransformContext) {
- s := tCtx.GetLogRecord().Attributes().PutEmptySlice("test")
- s.AppendEmpty().SetInt(9)
- s.AppendEmpty().SetInt(6)
- s.AppendEmpty().SetInt(3)
- },
- },
- {
- statement: `set(attributes["test"], Sort([Double(1.5), Double(10.2), Double(2.3), Double(0.5)]))`,
- want: func(tCtx ottllog.TransformContext) {
- s := tCtx.GetLogRecord().Attributes().PutEmptySlice("test")
- s.AppendEmpty().SetDouble(0.5)
- s.AppendEmpty().SetDouble(1.5)
- s.AppendEmpty().SetDouble(2.3)
- s.AppendEmpty().SetDouble(10.2)
- },
- },
- {
- statement: `set(attributes["test"], Sort([Int(11), Double(2.2), Double(-1)]))`,
- want: func(tCtx ottllog.TransformContext) {
- s := tCtx.GetLogRecord().Attributes().PutEmptySlice("test")
- s.AppendEmpty().SetDouble(-1)
- s.AppendEmpty().SetDouble(2.2)
- s.AppendEmpty().SetInt(11)
- },
- },
- {
- statement: `set(attributes["test"], Sort([false, Int(11), Double(2.2), "three"]))`,
- want: func(tCtx ottllog.TransformContext) {
- s := tCtx.GetLogRecord().Attributes().PutEmptySlice("test")
- s.AppendEmpty().SetInt(11)
- s.AppendEmpty().SetDouble(2.2)
- s.AppendEmpty().SetBool(false)
- s.AppendEmpty().SetStr("three")
- },
- },
- {
- statement: `set(span_id, SpanID(0x0000000000000000))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().SetSpanID(pcommon.NewSpanIDEmpty())
- },
- },
- {
- statement: `set(attributes["test"], Split(attributes["flags"], "|"))`,
- want: func(tCtx ottllog.TransformContext) {
- s := tCtx.GetLogRecord().Attributes().PutEmptySlice("test")
- s.AppendEmpty().SetStr("A")
- s.AppendEmpty().SetStr("B")
- s.AppendEmpty().SetStr("C")
- },
- },
- {
- statement: `set(attributes["test"], String("test"))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", "test")
- },
- },
- {
- statement: `set(attributes["test"], String(attributes["http.method"]))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", "get")
- },
- },
- {
- statement: `set(attributes["test"], String(span_id))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", "[1,2,3,4,5,6,7,8]")
- },
- },
- {
- statement: `set(attributes["test"], String([1,2,3]))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", "[1,2,3]")
- },
- },
- {
- statement: `set(attributes["test"], String(true))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", "true")
- },
- },
- {
- statement: `set(attributes["test"], Substring("pass", 0, 2))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", "pa")
- },
- },
- {
- statement: `set(trace_id, TraceID(0x00000000000000000000000000000000))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().SetTraceID(pcommon.NewTraceIDEmpty())
- },
- },
- {
- statement: `set(time, TruncateTime(time, Duration("1s")))`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().SetTimestamp(pcommon.NewTimestampFromTime(TestLogTimestamp.AsTime().Truncate(time.Second)))
- },
- },
- {
- statement: `set(attributes["test"], "pass") where UnixMicro(time) > 0`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", "pass")
- },
- },
- {
- statement: `set(attributes["test"], "pass") where UnixMilli(time) > 0`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", "pass")
- },
- },
- {
- statement: `set(attributes["test"], "pass") where UnixNano(time) > 0`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", "pass")
- },
- },
- {
- statement: `set(attributes["test"], "pass") where UnixSeconds(time) > 0`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", "pass")
- },
- },
- {
- statement: `set(attributes["test"], "pass") where IsString(UUID())`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", "pass")
- },
- },
- {
- statement: `set(attributes["test"], "\\")`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", "\\")
- },
- },
- {
- statement: `set(attributes["test"], "\\\\")`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", "\\\\")
- },
- },
- {
- statement: `set(attributes["test"], "\\\\\\")`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", "\\\\\\")
- },
- },
- {
- statement: `set(attributes["test"], "\\\\\\\\")`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", "\\\\\\\\")
- },
- },
- {
- statement: `set(attributes["test"], "\"")`,
- want: func(tCtx ottllog.TransformContext) {
- tCtx.GetLogRecord().Attributes().PutStr("test", `"`)
- },
- },
- {
- statement: `keep_keys(attributes["foo"], ["\\", "bar"])`,
- want: func(tCtx ottllog.TransformContext) {
- // keep_keys should see two arguments
- m := tCtx.GetLogRecord().Attributes().PutEmptyMap("foo")
- m.PutStr("bar", "pass")
- },
- },
- {
- statement: `set(attributes["test"], UserAgent("curl/7.81.0"))`,
- want: func(tCtx ottllog.TransformContext) {
- m := tCtx.GetLogRecord().Attributes().PutEmptyMap("test")
- m.PutStr("user_agent.original", "curl/7.81.0")
- m.PutStr("user_agent.name", "curl")
- m.PutStr("user_agent.version", "7.81.0")
- },
- },
- {
- statement: `set(attributes["test"], SliceToMap(attributes["things"], ["name"]))`,
- want: func(tCtx ottllog.TransformContext) {
- m := tCtx.GetLogRecord().Attributes().PutEmptyMap("test")
- thing1 := m.PutEmptyMap("foo")
- thing1.PutStr("name", "foo")
- thing1.PutInt("value", 2)
+ // message := logChildren.AppendEmpty().SetEmptyMap()
+ // message.PutStr("tag", "Message")
+ // message.PutStr("content", "This is a log message!")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], RemoveXML("This is a log message!", "/Log/Message"))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", ``)
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], Seconds(Duration("1m")))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutDouble("test", 60)
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], SHA1("pass"))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", "9d4e1e23bd5b727046a9e3b4b7db57bd8d6ee684")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], SHA256("pass"))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", "d74ff0ee8da3b9806b18c877dbf29bbde50b5bd8e4dad7a3a725000feb82e8f1")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], SHA512("pass"))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", "5b722b307fce6c944905d132691d5e4a2214b7fe92b738920eb3fce3a90420a19511c3010a0e7712b054daef5b57bad59ecbd93b3280f210578f547f4aed4d25")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], Sort(Split(attributes["flags"], "|"), "desc"))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // s := tCtx.GetLogRecord().Attributes().PutEmptySlice("test")
+ // s.AppendEmpty().SetStr("C")
+ // s.AppendEmpty().SetStr("B")
+ // s.AppendEmpty().SetStr("A")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], Sort([true, false, false]))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // s := tCtx.GetLogRecord().Attributes().PutEmptySlice("test")
+ // s.AppendEmpty().SetBool(false)
+ // s.AppendEmpty().SetBool(false)
+ // s.AppendEmpty().SetBool(true)
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], Sort([3, 6, 9], "desc"))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // s := tCtx.GetLogRecord().Attributes().PutEmptySlice("test")
+ // s.AppendEmpty().SetInt(9)
+ // s.AppendEmpty().SetInt(6)
+ // s.AppendEmpty().SetInt(3)
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], Sort([Double(1.5), Double(10.2), Double(2.3), Double(0.5)]))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // s := tCtx.GetLogRecord().Attributes().PutEmptySlice("test")
+ // s.AppendEmpty().SetDouble(0.5)
+ // s.AppendEmpty().SetDouble(1.5)
+ // s.AppendEmpty().SetDouble(2.3)
+ // s.AppendEmpty().SetDouble(10.2)
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], Sort([Int(11), Double(2.2), Double(-1)]))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // s := tCtx.GetLogRecord().Attributes().PutEmptySlice("test")
+ // s.AppendEmpty().SetDouble(-1)
+ // s.AppendEmpty().SetDouble(2.2)
+ // s.AppendEmpty().SetInt(11)
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], Sort([false, Int(11), Double(2.2), "three"]))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // s := tCtx.GetLogRecord().Attributes().PutEmptySlice("test")
+ // s.AppendEmpty().SetInt(11)
+ // s.AppendEmpty().SetDouble(2.2)
+ // s.AppendEmpty().SetBool(false)
+ // s.AppendEmpty().SetStr("three")
+ // },
+ // },
+ // {
+ // statement: `set(span_id, SpanID(0x0000000000000000))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().SetSpanID(pcommon.NewSpanIDEmpty())
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], Split(attributes["flags"], "|"))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // s := tCtx.GetLogRecord().Attributes().PutEmptySlice("test")
+ // s.AppendEmpty().SetStr("A")
+ // s.AppendEmpty().SetStr("B")
+ // s.AppendEmpty().SetStr("C")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], String("test"))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", "test")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], String(attributes["http.method"]))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", "get")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], String(span_id))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", "[1,2,3,4,5,6,7,8]")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], String([1,2,3]))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", "[1,2,3]")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], String(true))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", "true")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], Substring("pass", 0, 2))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", "pa")
+ // },
+ // },
+ // {
+ // statement: `set(trace_id, TraceID(0x00000000000000000000000000000000))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().SetTraceID(pcommon.NewTraceIDEmpty())
+ // },
+ // },
+ // {
+ // statement: `set(time, TruncateTime(time, Duration("1s")))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().SetTimestamp(pcommon.NewTimestampFromTime(TestLogTimestamp.AsTime().Truncate(time.Second)))
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], "pass") where UnixMicro(time) > 0`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", "pass")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], "pass") where UnixMilli(time) > 0`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", "pass")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], "pass") where UnixNano(time) > 0`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", "pass")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], "pass") where UnixSeconds(time) > 0`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", "pass")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], "pass") where IsString(UUID())`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", "pass")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], "\\")`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", "\\")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], "\\\\")`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", "\\\\")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], "\\\\\\")`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", "\\\\\\")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], "\\\\\\\\")`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", "\\\\\\\\")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], "\"")`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // tCtx.GetLogRecord().Attributes().PutStr("test", `"`)
+ // },
+ // },
+ // {
+ // statement: `keep_keys(attributes["foo"], ["\\", "bar"])`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // // keep_keys should see two arguments
+ // m := tCtx.GetLogRecord().Attributes().PutEmptyMap("foo")
+ // m.PutStr("bar", "pass")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], UserAgent("curl/7.81.0"))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // m := tCtx.GetLogRecord().Attributes().PutEmptyMap("test")
+ // m.PutStr("user_agent.original", "curl/7.81.0")
+ // m.PutStr("user_agent.name", "curl")
+ // m.PutStr("user_agent.version", "7.81.0")
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], SliceToMap(attributes["things"], ["name"]))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // m := tCtx.GetLogRecord().Attributes().PutEmptyMap("test")
+ // thing1 := m.PutEmptyMap("foo")
+ // thing1.PutStr("name", "foo")
+ // thing1.PutInt("value", 2)
- thing2 := m.PutEmptyMap("bar")
- thing2.PutStr("name", "bar")
- thing2.PutInt("value", 5)
- },
- },
- {
- statement: `set(attributes["test"], SliceToMap(attributes["things"], ["name"], ["value"]))`,
- want: func(tCtx ottllog.TransformContext) {
- m := tCtx.GetLogRecord().Attributes().PutEmptyMap("test")
- m.PutInt("foo", 2)
- m.PutInt("bar", 5)
- },
- },
+ // thing2 := m.PutEmptyMap("bar")
+ // thing2.PutStr("name", "bar")
+ // thing2.PutInt("value", 5)
+ // },
+ // },
+ // {
+ // statement: `set(attributes["test"], SliceToMap(attributes["things"], ["name"], ["value"]))`,
+ // want: func(tCtx ottllog.TransformContext) {
+ // m := tCtx.GetLogRecord().Attributes().PutEmptyMap("test")
+ // m.PutInt("foo", 2)
+ // m.PutInt("bar", 5)
+ // },
+ // },
}
for _, tt := range tests {
@@ -967,7 +967,7 @@ func Test_e2e_converters(t *testing.T) {
logParser, err := ottllog.NewParser(ottlfuncs.StandardFuncs[ottllog.TransformContext](), settings)
assert.NoError(t, err)
logStatements, err := logParser.ParseStatement(tt.statement)
- assert.NoError(t, err)
+ require.Nil(t, err)
tCtx := constructLogTransformContext()
_, _, _ = logStatements.Execute(context.Background(), tCtx)
diff --git a/pkg/ottl/functions.go b/pkg/ottl/functions.go
index 4ff92123c7e6..1199423c81f3 100644
--- a/pkg/ottl/functions.go
+++ b/pkg/ottl/functions.go
@@ -481,18 +481,29 @@ func (p *Parser[K]) buildArg(argVal value, argType reflect.Type) (any, error) {
case strings.HasPrefix(name, "Setter"):
fallthrough
case strings.HasPrefix(name, "GetSetter"):
- if argVal.Literal == nil || argVal.Literal.Path == nil {
- return nil, fmt.Errorf("must be a path")
- }
- np, err := p.newPath(argVal.Literal.Path)
- if err != nil {
- return nil, err
+ if argVal.Literal != nil && argVal.Literal.Path != nil {
+ np, err := p.newPath(argVal.Literal.Path)
+ if err != nil {
+ return nil, err
+ }
+ arg, err := p.parsePath(np)
+ if err != nil {
+ return nil, err
+ }
+ return arg, nil
}
- arg, err := p.parsePath(np)
- if err != nil {
- return nil, err
+ if argVal.ExpressionPath != nil {
+ np, err := p.newPath(argVal.ExpressionPath)
+ if err != nil {
+ return nil, err
+ }
+ arg, err := p.parsePath(np)
+ if err != nil {
+ return nil, err
+ }
+ return arg, nil
}
- return arg, nil
+ return nil, fmt.Errorf("must be a path")
case strings.HasPrefix(name, "Getter"):
arg, err := p.newGetter(argVal)
if err != nil {
diff --git a/pkg/ottl/grammar.go b/pkg/ottl/grammar.go
index a1e5eb53a81d..393ca2a100f8 100644
--- a/pkg/ottl/grammar.go
+++ b/pkg/ottl/grammar.go
@@ -234,6 +234,7 @@ func (a *argument) accept(v grammarVisitor) {
// mathExpression, function call, or literal.
type value struct {
IsNil *isNil `parser:"( @'nil'"`
+ ExpressionPath *path `parser:"| '$''{' @@ '}'"`
Literal *mathExprLiteral `parser:"| @@ (?! OpAddSub | OpMultDiv)"`
MathExpression *mathExpression `parser:"| @@"`
Bytes *byteSlice `parser:"| @Bytes"`
@@ -260,6 +261,9 @@ func (v *value) accept(vis grammarVisitor) {
i.accept(vis)
}
}
+ if v.ExpressionPath != nil {
+ vis.visitPath(v.ExpressionPath)
+ }
}
// path represents a telemetry path mathExpression.
@@ -486,6 +490,7 @@ func buildLexer() *lexer.StatefulDefinition {
{Name: `LBrace`, Pattern: `\{`},
{Name: `RBrace`, Pattern: `\}`},
{Name: `Colon`, Pattern: `\:`},
+ {Name: `Dollar`, Pattern: `\$`},
{Name: `Punct`, Pattern: `[,.\[\]]`},
{Name: `Uppercase`, Pattern: `[A-Z][A-Z0-9_]*`},
{Name: `Lowercase`, Pattern: `[a-z][a-z0-9_]*`},
diff --git a/pkg/ottl/lexer_test.go b/pkg/ottl/lexer_test.go
index b73d71d80e8f..927dab112e84 100644
--- a/pkg/ottl/lexer_test.go
+++ b/pkg/ottl/lexer_test.go
@@ -130,6 +130,15 @@ func Test_lexer(t *testing.T) {
{"String", `"bar"`},
{"RBrace", "}"},
}},
+ {"Expression path", `${foo["foo"]}`, false, []result{
+ {"Dollar", "$"},
+ {"LBrace", "{"},
+ {"Lowercase", "foo"},
+ {"Punct", "["},
+ {"String", `"foo"`},
+ {"Punct", "]"},
+ {"RBrace", "}"},
+ }},
}
for _, tt := range tests {
diff --git a/pkg/ottl/ottlfuncs/func_set.go b/pkg/ottl/ottlfuncs/func_set.go
index a0ce390a4788..4341fca9e034 100644
--- a/pkg/ottl/ottlfuncs/func_set.go
+++ b/pkg/ottl/ottlfuncs/func_set.go
@@ -11,7 +11,7 @@ import (
)
type SetArguments[K any] struct {
- Target ottl.Setter[K]
+ Target ottl.GetSetter[K]
Value ottl.Getter[K]
}
@@ -29,7 +29,7 @@ func createSetFunction[K any](_ ottl.FunctionContext, oArgs ottl.Arguments) (ott
return set(args.Target, args.Value), nil
}
-func set[K any](target ottl.Setter[K], value ottl.Getter[K]) ottl.ExprFunc[K] {
+func set[K any](target ottl.GetSetter[K], value ottl.Getter[K]) ottl.ExprFunc[K] {
return func(ctx context.Context, tCtx K) (any, error) {
val, err := value.Get(ctx, tCtx)
if err != nil {