Skip to content

Commit

Permalink
Fix connector logger zap kind key (open-telemetry#8878)
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu authored Nov 14, 2023
1 parent a4b01fd commit df8aaae
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 9 deletions.
13 changes: 13 additions & 0 deletions .chloggen/fixconnectorlogger.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: 'bug_fix'

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: "service"

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Fix connector logger zap kind key"

# One or more tracking issues or pull requests related to the change
issues: [8878]
16 changes: 16 additions & 0 deletions component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,22 @@ const (
KindConnector
)

func (k Kind) String() string {
switch k {
case KindReceiver:
return "Receiver"
case KindProcessor:
return "Processor"
case KindExporter:
return "Exporter"
case KindExtension:
return "Extension"
case KindConnector:
return "Connector"
}
return ""
}

// StabilityLevel represents the stability level of the component created by the factory.
// The stability level is used to determine if the component should be used in production
// or not. For more details see:
Expand Down
10 changes: 10 additions & 0 deletions component/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ import (
"github.com/stretchr/testify/assert"
)

func TestKindString(t *testing.T) {
assert.EqualValues(t, "", Kind(0).String())
assert.EqualValues(t, "Receiver", KindReceiver.String())
assert.EqualValues(t, "Processor", KindProcessor.String())
assert.EqualValues(t, "Exporter", KindExporter.String())
assert.EqualValues(t, "Extension", KindExtension.String())
assert.EqualValues(t, "Connector", KindConnector.String())
assert.EqualValues(t, "", Kind(100).String())
}

func TestStabilityLevelString(t *testing.T) {
assert.EqualValues(t, "Undefined", StabilityLevelUndefined.String())
assert.EqualValues(t, "Unmaintained", StabilityLevelUnmaintained.String())
Expand Down
16 changes: 7 additions & 9 deletions service/internal/components/loggers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@
package components // import "go.opentelemetry.io/collector/service/internal/components"

import (
"strings"

"go.uber.org/zap"

"go.opentelemetry.io/collector/component"
)

const (
zapKindKey = "kind"
zapKindReceiver = "receiver"
zapKindProcessor = "processor"
zapKindExporter = "exporter"
zapKindExtension = "extension"
zapNameKey = "name"
zapDataTypeKey = "data_type"
zapStabilityKey = "stability"
Expand All @@ -25,34 +23,34 @@ const (

func ReceiverLogger(logger *zap.Logger, id component.ID, dt component.DataType) *zap.Logger {
return logger.With(
zap.String(zapKindKey, zapKindReceiver),
zap.String(zapKindKey, strings.ToLower(component.KindReceiver.String())),
zap.String(zapNameKey, id.String()),
zap.String(zapDataTypeKey, string(dt)))
}

func ProcessorLogger(logger *zap.Logger, id component.ID, pipelineID component.ID) *zap.Logger {
return logger.With(
zap.String(zapKindKey, zapKindProcessor),
zap.String(zapKindKey, strings.ToLower(component.KindProcessor.String())),
zap.String(zapNameKey, id.String()),
zap.String(zapPipelineKey, pipelineID.String()))
}

func ExporterLogger(logger *zap.Logger, id component.ID, dt component.DataType) *zap.Logger {
return logger.With(
zap.String(zapKindKey, zapKindExporter),
zap.String(zapKindKey, strings.ToLower(component.KindExporter.String())),
zap.String(zapDataTypeKey, string(dt)),
zap.String(zapNameKey, id.String()))
}

func ExtensionLogger(logger *zap.Logger, id component.ID) *zap.Logger {
return logger.With(
zap.String(zapKindKey, zapKindExtension),
zap.String(zapKindKey, strings.ToLower(component.KindExtension.String())),
zap.String(zapNameKey, id.String()))
}

func ConnectorLogger(logger *zap.Logger, id component.ID, expDT, rcvDT component.DataType) *zap.Logger {
return logger.With(
zap.String(zapKindKey, zapKindExporter),
zap.String(zapKindKey, strings.ToLower(component.KindConnector.String())),
zap.String(zapNameKey, id.String()),
zap.String(zapExporterInPipeline, string(expDT)),
zap.String(zapReceiverInPipeline, string(rcvDT)))
Expand Down

0 comments on commit df8aaae

Please sign in to comment.