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

[chore][pkg/stanza] Cleanup copy operator files #32061

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
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
33 changes: 33 additions & 0 deletions pkg/stanza/operator/transformer/copy/transformer.go
Original file line number Diff line number Diff line change
@@ -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)
}