diff --git a/.chloggen/ottl-rename-trace-context.yaml b/.chloggen/ottl-rename-trace-context.yaml new file mode 100755 index 000000000000..9ea35d73861d --- /dev/null +++ b/.chloggen/ottl-rename-trace-context.yaml @@ -0,0 +1,16 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: breaking + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: pkg/ottl + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Renames `ottltraces` to `ottlspan` + +# One or more tracking issues related to the change +issues: [16241] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: diff --git a/pkg/ottl/contexts/ottltraces/README.md b/pkg/ottl/contexts/ottlspan/README.md similarity index 88% rename from pkg/ottl/contexts/ottltraces/README.md rename to pkg/ottl/contexts/ottlspan/README.md index 3fad4379217c..8987cfbf6de1 100644 --- a/pkg/ottl/contexts/ottltraces/README.md +++ b/pkg/ottl/contexts/ottlspan/README.md @@ -1,9 +1,9 @@ -# Traces Context +___# Span Context -The Traces Context is a Context implementation for [pdata Traces](https://github.com/open-telemetry/opentelemetry-collector/tree/main/pdata/ptrace), the collector's internal representation for OTLP trace data. This Context should be used when interacted with OTLP traces. +The Span Context is a Context implementation for [pdata Spans](https://github.com/open-telemetry/opentelemetry-collector/tree/main/pdata/ptrace), the collector's internal representation for OTLP span data. This Context should be used when interacted with OTLP spans. ## Paths -In general, the Traces Context supports accessing pdata using the field names from the [traces proto](https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/trace/v1/trace.proto). All integers are returned and set via `int64`. All doubles are returned and set via `float64`. +In general, the Span Context supports accessing pdata using the field names from the [traces proto](https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/trace/v1/trace.proto). All integers are returned and set via `int64`. All doubles are returned and set via `float64`. All TraceIDs and SpanIDs are returned as pdata [SpanID](https://github.com/open-telemetry/opentelemetry-collector/blob/main/pdata/pcommon/spanid.go) and [TraceID](https://github.com/open-telemetry/opentelemetry-collector/blob/main/pdata/pcommon/traceid.go) types. Use the [SpanID function](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/pkg/ottl/ottlfuncs/README.md#spanid) and [TraceID function](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/pkg/ottl/ottlfuncs/README.md#traceid) when interacting with pdata representations of SpanID and TraceID. When checking for nil, instead check against an empty byte slice (`SpanID(0x0000000000000000)` and `TraceID(0x00000000000000000000000000000000)`). @@ -35,4 +35,4 @@ The following fields are the exception. ## Enums -The Traces Context supports the enum names from the traces proto. +The Span Context supports the enum names from the [traces proto](https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/trace/v1/trace.proto). diff --git a/pkg/ottl/contexts/ottltraces/traces.go b/pkg/ottl/contexts/ottlspan/span.go similarity index 96% rename from pkg/ottl/contexts/ottltraces/traces.go rename to pkg/ottl/contexts/ottlspan/span.go index 549221eebcb1..3f30d9ff4943 100644 --- a/pkg/ottl/contexts/ottltraces/traces.go +++ b/pkg/ottl/contexts/ottlspan/span.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package ottltraces // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottltraces" +package ottlspan // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlspan" import ( "fmt" diff --git a/pkg/ottl/contexts/ottltraces/traces_test.go b/pkg/ottl/contexts/ottlspan/span_test.go similarity index 99% rename from pkg/ottl/contexts/ottltraces/traces_test.go rename to pkg/ottl/contexts/ottlspan/span_test.go index 11d1f74d86da..62b5fe4319e0 100644 --- a/pkg/ottl/contexts/ottltraces/traces_test.go +++ b/pkg/ottl/contexts/ottlspan/span_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package ottltraces +package ottlspan import ( "context" diff --git a/processor/routingprocessor/traces.go b/processor/routingprocessor/traces.go index 97206856c938..23f7c6b2ec9b 100644 --- a/processor/routingprocessor/traces.go +++ b/processor/routingprocessor/traces.go @@ -24,7 +24,7 @@ import ( "go.uber.org/multierr" "go.uber.org/zap" - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottltraces" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlspan" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/routingprocessor/internal/common" ) @@ -35,7 +35,7 @@ type tracesProcessor struct { config *Config extractor extractor - router router[component.TracesExporter, ottltraces.TransformContext] + router router[component.TracesExporter, ottlspan.TransformContext] } func newTracesProcessor(settings component.TelemetrySettings, config component.ProcessorConfig) *tracesProcessor { @@ -44,11 +44,11 @@ func newTracesProcessor(settings component.TelemetrySettings, config component.P return &tracesProcessor{ logger: settings.Logger, config: cfg, - router: newRouter[component.TracesExporter, ottltraces.TransformContext]( + router: newRouter[component.TracesExporter, ottlspan.TransformContext]( cfg.Table, cfg.DefaultExporters, settings, - ottltraces.NewParser(common.Functions[ottltraces.TransformContext](), settings), + ottlspan.NewParser(common.Functions[ottlspan.TransformContext](), settings), ), extractor: newExtractor(cfg.FromAttribute, settings.Logger), } @@ -92,7 +92,7 @@ func (p *tracesProcessor) route(ctx context.Context, t ptrace.Traces) error { var errs error for i := 0; i < t.ResourceSpans().Len(); i++ { rspans := t.ResourceSpans().At(i) - stx := ottltraces.NewTransformContext( + stx := ottlspan.NewTransformContext( ptrace.Span{}, pcommon.InstrumentationScope{}, rspans.Resource(), diff --git a/processor/transformprocessor/README.md b/processor/transformprocessor/README.md index 4c0141eeb064..aadc8d3b9e19 100644 --- a/processor/transformprocessor/README.md +++ b/processor/transformprocessor/README.md @@ -40,7 +40,7 @@ Valid values for `context` are: | Signal | Context Values | |-------------------|------------------------------------------------| -| trace_statements | `resource`, `scope`, `trace`, and `spanevent` | +| trace_statements | `resource`, `scope`, `span`, and `spanevent` | | metric_statements | `resource`, `scope`, `metric`, and `datapoint` | | log_statements | `resource`, `scope`, and `log` | @@ -105,7 +105,7 @@ The contexts allow the OTTL to interact with the underlying telemetry data in it - [Resource Context](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/ottl/contexts/ottlresource) - [Scope Context](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/ottl/contexts/ottlscope) -- [Traces Context](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/ottl/contexts/ottltraces) +- [Span Context](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/ottl/contexts/ottlspan) - [SpanEvent Context](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/ottl/contexts/ottlspanevent) - [Metric Context](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/ottl/contexts/ottlmetric) - [DataPoint Context](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/ottl/contexts/ottldatapoint) diff --git a/processor/transformprocessor/config.go b/processor/transformprocessor/config.go index f492efd8ad9c..de290d71cc27 100644 --- a/processor/transformprocessor/config.go +++ b/processor/transformprocessor/config.go @@ -23,7 +23,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottldatapoint" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottllogs" - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottltraces" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlspan" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/common" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/logs" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/metrics" @@ -60,8 +60,8 @@ func (c *Config) Validate() error { } if len(c.Traces.Statements) > 0 { - ottltracesp := ottltraces.NewParser(traces.Functions(), component.TelemetrySettings{Logger: zap.NewNop()}) - _, err := ottltracesp.ParseStatements(c.Traces.Statements) + ottlspanp := ottlspan.NewParser(traces.Functions(), component.TelemetrySettings{Logger: zap.NewNop()}) + _, err := ottlspanp.ParseStatements(c.Traces.Statements) if err != nil { return err } diff --git a/processor/transformprocessor/config_test.go b/processor/transformprocessor/config_test.go index f334dc9a6f81..9c9e4d592640 100644 --- a/processor/transformprocessor/config_test.go +++ b/processor/transformprocessor/config_test.go @@ -51,7 +51,7 @@ func TestLoadConfig(t *testing.T) { }, TraceStatements: []common.ContextStatements{ { - Context: "trace", + Context: "span", Statements: []string{ `set(name, "bear") where attributes["http.path"] == "/animal"`, `keep_keys(attributes, ["http.method", "http.path"])`, diff --git a/processor/transformprocessor/internal/common/config.go b/processor/transformprocessor/internal/common/config.go index 75c159703e2f..acf74d374918 100644 --- a/processor/transformprocessor/internal/common/config.go +++ b/processor/transformprocessor/internal/common/config.go @@ -23,7 +23,7 @@ type ContextID string const ( Resource ContextID = "resource" Scope ContextID = "scope" - Trace ContextID = "trace" + Span ContextID = "span" SpanEvent ContextID = "spanevent" Metric ContextID = "metric" DataPoint ContextID = "datapoint" @@ -33,7 +33,7 @@ const ( func (c *ContextID) UnmarshalText(text []byte) error { str := ContextID(strings.ToLower(string(text))) switch str { - case Resource, Scope, Trace, SpanEvent, Metric, DataPoint, Log: + case Resource, Scope, Span, SpanEvent, Metric, DataPoint, Log: *c = str return nil default: diff --git a/processor/transformprocessor/internal/common/traces.go b/processor/transformprocessor/internal/common/traces.go index aa1f5d3819e5..89c8f57f520c 100644 --- a/processor/transformprocessor/internal/common/traces.go +++ b/processor/transformprocessor/internal/common/traces.go @@ -24,13 +24,13 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlresource" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlscope" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlspan" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlspanevent" - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottltraces" ) var _ consumer.Traces = &traceStatements{} -type traceStatements []*ottl.Statement[ottltraces.TransformContext] +type traceStatements []*ottl.Statement[ottlspan.TransformContext] func (t traceStatements) Capabilities() consumer.Capabilities { return consumer.Capabilities{ @@ -45,7 +45,7 @@ func (t traceStatements) ConsumeTraces(ctx context.Context, td ptrace.Traces) er sspans := rspans.ScopeSpans().At(j) spans := sspans.Spans() for k := 0; k < spans.Len(); k++ { - tCtx := ottltraces.NewTransformContext(spans.At(k), sspans.Scope(), rspans.Resource()) + tCtx := ottlspan.NewTransformContext(spans.At(k), sspans.Scope(), rspans.Resource()) for _, statement := range t { _, _, err := statement.Execute(ctx, tCtx) if err != nil { @@ -94,7 +94,7 @@ func (s spanEventStatements) ConsumeTraces(ctx context.Context, td ptrace.Traces type TraceParserCollection struct { parserCollection - traceParser ottl.Parser[ottltraces.TransformContext] + spanParser ottl.Parser[ottlspan.TransformContext] spanEventParser ottl.Parser[ottlspanevent.TransformContext] } @@ -107,7 +107,7 @@ func NewTraceParserCollection(functions map[string]interface{}, settings compone resourceParser: ottlresource.NewParser(ResourceFunctions(), settings), scopeParser: ottlscope.NewParser(ScopeFunctions(), settings), }, - traceParser: ottltraces.NewParser(functions, settings), + spanParser: ottlspan.NewParser(functions, settings), } for _, op := range options { @@ -122,8 +122,8 @@ func NewTraceParserCollection(functions map[string]interface{}, settings compone func (pc TraceParserCollection) ParseContextStatements(contextStatements ContextStatements) (consumer.Traces, error) { switch contextStatements.Context { - case Trace: - tStatements, err := pc.traceParser.ParseStatements(contextStatements.Statements) + case Span: + tStatements, err := pc.spanParser.ParseStatements(contextStatements.Statements) if err != nil { return nil, err } diff --git a/processor/transformprocessor/internal/traces/functions.go b/processor/transformprocessor/internal/traces/functions.go index 2c714d0ef2b0..1d6fe68dc50b 100644 --- a/processor/transformprocessor/internal/traces/functions.go +++ b/processor/transformprocessor/internal/traces/functions.go @@ -15,11 +15,11 @@ package traces // import "github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/traces" import ( - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottltraces" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlspan" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/common" ) func Functions() map[string]interface{} { // No trace-only functions yet. - return common.Functions[ottltraces.TransformContext]() + return common.Functions[ottlspan.TransformContext]() } diff --git a/processor/transformprocessor/internal/traces/functions_test.go b/processor/transformprocessor/internal/traces/functions_test.go index 1b4e6c748e97..715184d95c01 100644 --- a/processor/transformprocessor/internal/traces/functions_test.go +++ b/processor/transformprocessor/internal/traces/functions_test.go @@ -20,12 +20,12 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottltraces" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlspan" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/common" ) func Test_DefaultFunctions(t *testing.T) { - expected := common.Functions[ottltraces.TransformContext]() + expected := common.Functions[ottlspan.TransformContext]() actual := Functions() require.Equal(t, len(expected), len(actual)) for k := range actual { diff --git a/processor/transformprocessor/internal/traces/processor.go b/processor/transformprocessor/internal/traces/processor.go index ac6af5cc1403..efae98c2eae8 100644 --- a/processor/transformprocessor/internal/traces/processor.go +++ b/processor/transformprocessor/internal/traces/processor.go @@ -22,19 +22,19 @@ import ( "go.opentelemetry.io/collector/pdata/ptrace" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottltraces" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlspan" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/common" ) type Processor struct { contexts []consumer.Traces // Deprecated. Use contexts instead - statements []*ottl.Statement[ottltraces.TransformContext] + statements []*ottl.Statement[ottlspan.TransformContext] } func NewProcessor(statements []string, contextStatements []common.ContextStatements, settings component.TelemetrySettings) (*Processor, error) { if len(statements) > 0 { - ottlp := ottltraces.NewParser(Functions(), settings) + ottlp := ottlspan.NewParser(Functions(), settings) parsedStatements, err := ottlp.ParseStatements(statements) if err != nil { return nil, err @@ -71,7 +71,7 @@ func (p *Processor) ProcessTraces(ctx context.Context, td ptrace.Traces) (ptrace sspan := rspans.ScopeSpans().At(j) spans := sspan.Spans() for k := 0; k < spans.Len(); k++ { - tCtx := ottltraces.NewTransformContext(spans.At(k), sspan.Scope(), rspans.Resource()) + tCtx := ottlspan.NewTransformContext(spans.At(k), sspan.Scope(), rspans.Resource()) for _, statement := range p.statements { _, _, err := statement.Execute(ctx, tCtx) if err != nil { diff --git a/processor/transformprocessor/internal/traces/processor_test.go b/processor/transformprocessor/internal/traces/processor_test.go index 6df8b49d9036..31d5d106321d 100644 --- a/processor/transformprocessor/internal/traces/processor_test.go +++ b/processor/transformprocessor/internal/traces/processor_test.go @@ -338,7 +338,7 @@ func Test_ProcessTraces_TraceContext(t *testing.T) { for _, tt := range tests { t.Run(tt.statement, func(t *testing.T) { td := constructTraces() - processor, err := NewProcessor(nil, []common.ContextStatements{{Context: "trace", Statements: []string{tt.statement}}}, componenttest.NewNopTelemetrySettings()) + processor, err := NewProcessor(nil, []common.ContextStatements{{Context: "span", Statements: []string{tt.statement}}}, componenttest.NewNopTelemetrySettings()) assert.NoError(t, err) _, err = processor.ProcessTraces(context.Background(), td) @@ -368,7 +368,7 @@ func Test_ProcessTraces_MixContext(t *testing.T) { }, }, { - Context: "trace", + Context: "span", Statements: []string{ `set(attributes["test"], "pass") where resource.attributes["test"] == "pass"`, }, @@ -390,7 +390,7 @@ func Test_ProcessTraces_MixContext(t *testing.T) { }, }, { - Context: "trace", + Context: "span", Statements: []string{ `set(attributes["test"], "pass") where instrumentation_scope.attributes["test"] == "pass"`, }, @@ -406,7 +406,7 @@ func Test_ProcessTraces_MixContext(t *testing.T) { name: "order matters", contextStatments: []common.ContextStatements{ { - Context: "trace", + Context: "span", Statements: []string{ `set(attributes["test"], "pass") where instrumentation_scope.attributes["test"] == "pass"`, }, @@ -432,7 +432,7 @@ func Test_ProcessTraces_MixContext(t *testing.T) { }, }, { - Context: "trace", + Context: "span", Statements: []string{ `set(attributes["test"], "pass") where instrumentation_scope.attributes["test"] == "pass"`, }, diff --git a/processor/transformprocessor/testdata/config.yaml b/processor/transformprocessor/testdata/config.yaml index ba38bcf0a157..4432c39877f8 100644 --- a/processor/transformprocessor/testdata/config.yaml +++ b/processor/transformprocessor/testdata/config.yaml @@ -1,6 +1,6 @@ transform: trace_statements: - - context: trace + - context: span statements: - set(name, "bear") where attributes["http.path"] == "/animal" - keep_keys(attributes, ["http.method", "http.path"]) @@ -40,7 +40,7 @@ transform/deprecated_format: transform/using_both_formats: trace_statements: - - context: trace + - context: span statements: - set(name, "bear") where attributes["http.path"] == "/animal" - keep_keys(attributes, ["http.method", "http.path"]) @@ -65,7 +65,7 @@ transform/bad_syntax_metric: transform/bad_syntax_trace: trace_statements: - - context: trace + - context: span statements: - set(name, "bear" where attributes["http.path"] == "/animal" - keep_keys(attributes, ["http.method", "http.path"]) @@ -86,7 +86,7 @@ transform/unknown_function_metric: transform/unknown_function_trace: trace_statements: - - context: trace + - context: span statements: - set(name, "bear") where attributes["http.path"] == "/animal" - not_a_function(attributes, ["http.method", "http.path"])