Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
[chore][pkg/stanza] Cleanup copy operator files (open-telemetry#32061)
Browse files Browse the repository at this point in the history
Contributes to open-telemetry#32058
  • Loading branch information
djaglowski authored and pull[bot] committed Apr 16, 2024
1 parent 9d887ab commit 5537676
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 22 deletions.
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)
}

0 comments on commit 5537676

Please sign in to comment.