Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pkg/ottl] Rename ottltraces to ottlspan #16241

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .chloggen/ottl-rename-trace-context.yaml
Original file line number Diff line number Diff line change
@@ -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:
Original file line number Diff line number Diff line change
@@ -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)`).

Expand Down Expand Up @@ -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).
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package ottltraces
package ottlspan

import (
"context"
Expand Down
10 changes: 5 additions & 5 deletions processor/routingprocessor/traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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 {
Expand All @@ -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),
}
Expand Down Expand Up @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions processor/transformprocessor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |

Expand Down Expand Up @@ -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) <!-- markdown-link-check-disable-line -->
- [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) <!-- markdown-link-check-disable-line -->
Expand Down
6 changes: 3 additions & 3 deletions processor/transformprocessor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion processor/transformprocessor/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"])`,
Expand Down
4 changes: 2 additions & 2 deletions processor/transformprocessor/internal/common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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:
Expand Down
14 changes: 7 additions & 7 deletions processor/transformprocessor/internal/common/traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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 {
Expand Down Expand Up @@ -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]
}

Expand All @@ -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 {
Expand All @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions processor/transformprocessor/internal/traces/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions processor/transformprocessor/internal/traces/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions processor/transformprocessor/internal/traces/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"`,
},
Expand All @@ -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"`,
},
Expand All @@ -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"`,
},
Expand All @@ -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"`,
},
Expand Down
8 changes: 4 additions & 4 deletions processor/transformprocessor/testdata/config.yaml
Original file line number Diff line number Diff line change
@@ -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"])
Expand Down Expand Up @@ -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"])
Expand All @@ -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"])
Expand All @@ -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"])
Expand Down