diff --git a/pkg/stanza/operator/transformer/copy/copy.go b/pkg/stanza/operator/transformer/copy/config.go similarity index 73% rename from pkg/stanza/operator/transformer/copy/copy.go rename to pkg/stanza/operator/transformer/copy/config.go index 9c08bb1de85c5..bb1703048ec29 100644 --- a/pkg/stanza/operator/transformer/copy/copy.go +++ b/pkg/stanza/operator/transformer/copy/config.go @@ -4,7 +4,6 @@ package copy // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/transformer/copy" import ( - "context" "fmt" "go.uber.org/zap" @@ -60,24 +59,3 @@ func (c Config) Build(logger *zap.SugaredLogger) (operator.Operator, error) { To: c.To, }, nil } - -// Transformer copies a value from one field and creates a new field with that value -type Transformer struct { - helper.TransformerOperator - From entry.Field - To entry.Field -} - -// Process will process an entry with a copy transformation. -func (p *Transformer) Process(ctx context.Context, entry *entry.Entry) error { - return p.ProcessWith(ctx, entry, p.Transform) -} - -// Transform will apply the copy operation to an entry -func (p *Transformer) Transform(e *entry.Entry) error { - val, exist := p.From.Get(e) - if !exist { - return fmt.Errorf("copy: from field does not exist in this entry: %s", p.From.String()) - } - return p.To.Set(e, val) -} diff --git a/pkg/stanza/operator/transformer/copy/transformer.go b/pkg/stanza/operator/transformer/copy/transformer.go new file mode 100644 index 0000000000000..b7af87cfcd387 --- /dev/null +++ b/pkg/stanza/operator/transformer/copy/transformer.go @@ -0,0 +1,33 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package copy // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/transformer/copy" + +import ( + "context" + "fmt" + + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/entry" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/helper" +) + +// Transformer copies a value from one field and creates a new field with that value +type Transformer struct { + helper.TransformerOperator + From entry.Field + To entry.Field +} + +// Process will process an entry with a copy transformation. +func (t *Transformer) Process(ctx context.Context, entry *entry.Entry) error { + return t.ProcessWith(ctx, entry, t.Transform) +} + +// Transform will apply the copy operation to an entry +func (t *Transformer) Transform(e *entry.Entry) error { + val, exist := t.From.Get(e) + if !exist { + return fmt.Errorf("copy: from field does not exist in this entry: %s", t.From.String()) + } + return t.To.Set(e, val) +} diff --git a/pkg/stanza/operator/transformer/copy/copy_test.go b/pkg/stanza/operator/transformer/copy/transformer_test.go similarity index 100% rename from pkg/stanza/operator/transformer/copy/copy_test.go rename to pkg/stanza/operator/transformer/copy/transformer_test.go