Skip to content

Commit df8aaae

Browse files
authored
Fix connector logger zap kind key (open-telemetry#8878)
Signed-off-by: Bogdan Drutu <[email protected]>
1 parent a4b01fd commit df8aaae

File tree

4 files changed

+46
-9
lines changed

4 files changed

+46
-9
lines changed

.chloggen/fixconnectorlogger.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: 'bug_fix'
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
7+
component: "service"
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: "Fix connector logger zap kind key"
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [8878]

component/component.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,22 @@ const (
9696
KindConnector
9797
)
9898

99+
func (k Kind) String() string {
100+
switch k {
101+
case KindReceiver:
102+
return "Receiver"
103+
case KindProcessor:
104+
return "Processor"
105+
case KindExporter:
106+
return "Exporter"
107+
case KindExtension:
108+
return "Extension"
109+
case KindConnector:
110+
return "Connector"
111+
}
112+
return ""
113+
}
114+
99115
// StabilityLevel represents the stability level of the component created by the factory.
100116
// The stability level is used to determine if the component should be used in production
101117
// or not. For more details see:

component/component_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ import (
99
"github.com/stretchr/testify/assert"
1010
)
1111

12+
func TestKindString(t *testing.T) {
13+
assert.EqualValues(t, "", Kind(0).String())
14+
assert.EqualValues(t, "Receiver", KindReceiver.String())
15+
assert.EqualValues(t, "Processor", KindProcessor.String())
16+
assert.EqualValues(t, "Exporter", KindExporter.String())
17+
assert.EqualValues(t, "Extension", KindExtension.String())
18+
assert.EqualValues(t, "Connector", KindConnector.String())
19+
assert.EqualValues(t, "", Kind(100).String())
20+
}
21+
1222
func TestStabilityLevelString(t *testing.T) {
1323
assert.EqualValues(t, "Undefined", StabilityLevelUndefined.String())
1424
assert.EqualValues(t, "Unmaintained", StabilityLevelUnmaintained.String())

service/internal/components/loggers.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,15 @@
44
package components // import "go.opentelemetry.io/collector/service/internal/components"
55

66
import (
7+
"strings"
8+
79
"go.uber.org/zap"
810

911
"go.opentelemetry.io/collector/component"
1012
)
1113

1214
const (
1315
zapKindKey = "kind"
14-
zapKindReceiver = "receiver"
15-
zapKindProcessor = "processor"
16-
zapKindExporter = "exporter"
17-
zapKindExtension = "extension"
1816
zapNameKey = "name"
1917
zapDataTypeKey = "data_type"
2018
zapStabilityKey = "stability"
@@ -25,34 +23,34 @@ const (
2523

2624
func ReceiverLogger(logger *zap.Logger, id component.ID, dt component.DataType) *zap.Logger {
2725
return logger.With(
28-
zap.String(zapKindKey, zapKindReceiver),
26+
zap.String(zapKindKey, strings.ToLower(component.KindReceiver.String())),
2927
zap.String(zapNameKey, id.String()),
3028
zap.String(zapDataTypeKey, string(dt)))
3129
}
3230

3331
func ProcessorLogger(logger *zap.Logger, id component.ID, pipelineID component.ID) *zap.Logger {
3432
return logger.With(
35-
zap.String(zapKindKey, zapKindProcessor),
33+
zap.String(zapKindKey, strings.ToLower(component.KindProcessor.String())),
3634
zap.String(zapNameKey, id.String()),
3735
zap.String(zapPipelineKey, pipelineID.String()))
3836
}
3937

4038
func ExporterLogger(logger *zap.Logger, id component.ID, dt component.DataType) *zap.Logger {
4139
return logger.With(
42-
zap.String(zapKindKey, zapKindExporter),
40+
zap.String(zapKindKey, strings.ToLower(component.KindExporter.String())),
4341
zap.String(zapDataTypeKey, string(dt)),
4442
zap.String(zapNameKey, id.String()))
4543
}
4644

4745
func ExtensionLogger(logger *zap.Logger, id component.ID) *zap.Logger {
4846
return logger.With(
49-
zap.String(zapKindKey, zapKindExtension),
47+
zap.String(zapKindKey, strings.ToLower(component.KindExtension.String())),
5048
zap.String(zapNameKey, id.String()))
5149
}
5250

5351
func ConnectorLogger(logger *zap.Logger, id component.ID, expDT, rcvDT component.DataType) *zap.Logger {
5452
return logger.With(
55-
zap.String(zapKindKey, zapKindExporter),
53+
zap.String(zapKindKey, strings.ToLower(component.KindConnector.String())),
5654
zap.String(zapNameKey, id.String()),
5755
zap.String(zapExporterInPipeline, string(expDT)),
5856
zap.String(zapReceiverInPipeline, string(rcvDT)))

0 commit comments

Comments
 (0)