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

Fix connector logger zap kind key #8878

Merged
merged 1 commit into from
Nov 14, 2023
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
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())),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using ToLower just to make sure we are not changing the previous strings. The String() method returns upper case to be consistent with other funcs like StabilityLevel.

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
Loading