@@ -76,6 +76,7 @@ type otelTeeCoreWithAttributes struct {
76
76
lp log.LoggerProvider
77
77
scopeName string
78
78
level zapcore.Level
79
+ wrapper func (zapcore.Core ) zapcore.Core
79
80
}
80
81
81
82
var _ coreWithAttributes = (* otelTeeCoreWithAttributes )(nil )
@@ -84,7 +85,7 @@ var _ coreWithAttributes = (*otelTeeCoreWithAttributes)(nil)
84
85
// logs, component attributes are injected as instrumentation scope attributes.
85
86
//
86
87
// This is used when service::telemetry::logs::processors is configured.
87
- func NewOTelTeeCoreWithAttributes (consoleCore zapcore.Core , lp log.LoggerProvider , scopeName string , level zapcore.Level , attrs attribute.Set ) zapcore.Core {
88
+ func NewOTelTeeCoreWithAttributes (consoleCore zapcore.Core , lp log.LoggerProvider , scopeName string , level zapcore.Level , attrs attribute.Set , wrapper func (zapcore. Core ) zapcore. Core ) zapcore.Core {
88
89
// TODO: Use `otelzap.WithAttributes` and remove `LoggerProviderWithAttributes`
89
90
// once we've upgraded to otelzap v0.11.0.
90
91
lpwa := LoggerProviderWithAttributes (lp , attrs )
@@ -97,45 +98,17 @@ func NewOTelTeeCoreWithAttributes(consoleCore zapcore.Core, lp log.LoggerProvide
97
98
}
98
99
99
100
return & otelTeeCoreWithAttributes {
100
- Core : zapcore .NewTee (consoleCore , otelCore ),
101
+ Core : zapcore .NewTee (consoleCore , wrapper ( otelCore ) ),
101
102
consoleCore : consoleCore ,
102
103
lp : lp ,
103
104
scopeName : scopeName ,
104
105
level : level ,
106
+ wrapper : wrapper ,
105
107
}
106
108
}
107
109
108
110
func (ocwa * otelTeeCoreWithAttributes ) withAttributeSet (attrs attribute.Set ) zapcore.Core {
109
- return NewOTelTeeCoreWithAttributes (
110
- tryWithAttributeSet (ocwa .consoleCore , attrs ),
111
- ocwa .lp , ocwa .scopeName , ocwa .level ,
112
- attrs ,
113
- )
114
- }
115
-
116
- type wrapperCoreWithAttributes struct {
117
- zapcore.Core
118
- from zapcore.Core
119
- wrapper func (zapcore.Core ) zapcore.Core
120
- }
121
-
122
- var _ coreWithAttributes = (* wrapperCoreWithAttributes )(nil )
123
-
124
- // NewWrapperCoreWithAttributes applies a wrapper function to a core, similar to [zap.WrapCore]. The resulting wrapped core
125
- // allows setting component attributes on the inner core and reapplying the wrapper function when
126
- // needed.
127
- //
128
- // This is used when adding [zapcore.NewSamplerWithOptions] to our logger stack.
129
- func NewWrapperCoreWithAttributes (from zapcore.Core , wrapper func (zapcore.Core ) zapcore.Core ) zapcore.Core {
130
- return & wrapperCoreWithAttributes {
131
- Core : wrapper (from ),
132
- from : from ,
133
- wrapper : wrapper ,
134
- }
135
- }
136
-
137
- func (wcwa * wrapperCoreWithAttributes ) withAttributeSet (attrs attribute.Set ) zapcore.Core {
138
- return NewWrapperCoreWithAttributes (tryWithAttributeSet (wcwa .from , attrs ), wcwa .wrapper )
111
+ return NewOTelTeeCoreWithAttributes (tryWithAttributeSet (ocwa .consoleCore , attrs ), ocwa .lp , ocwa .scopeName , ocwa .level , attrs , ocwa .wrapper )
139
112
}
140
113
141
114
// ZapLoggerWithAttributes creates a Zap Logger with a new set of injected component attributes.
0 commit comments