Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 8 additions & 0 deletions service/telemetry/internal/migration/v0.3.0.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ type LogsConfigV030 struct {
// Processors allow configuration of log record processors to emit logs to
// any number of supported backends.
Processors []config.LogRecordProcessor `mapstructure:"processors,omitempty"`

// ResourceAsZapFields indicates whether resource attributes should be added as zap fields.
// If true, resource attributes will be added to logs exported through the LoggerProvider
// and also to logs written to stdout/stderr.
// If false, resource attributes neither be added to logs exported through the LoggerProvider nor
// to the logs written to stdout/stderr.
// (default = true)
ResourceAsZapFields bool `mapstructure:"resource_as_zap_field"`
}

// LogsSamplingConfig sets a sampling strategy for the logger. Sampling caps the
Expand Down
2 changes: 1 addition & 1 deletion service/telemetry/otelconftelemetry/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func createLogger(
// add them to the logger using With, because that would apply to all logs,
// even ones exported through the core that wraps the LoggerProvider,
// meaning that the attributes would be exported twice.
if res != nil && len(res.Attributes()) > 0 {
if cfg.Logs.ResourceAsZapFields && res != nil && len(res.Attributes()) > 0 {
logger = logger.WithOptions(zap.WrapCore(func(c zapcore.Core) zapcore.Core {
var fields []zap.Field
for _, attr := range res.Attributes() {
Expand Down
16 changes: 16 additions & 0 deletions service/telemetry/otelconftelemetry/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,22 @@ func TestCreateLogger(t *testing.T) {
},
},
},
{
name: "log config with resource_as_zap_field disabled",
cfg: Config{
Logs: LogsConfig{
Level: zapcore.InfoLevel,
Development: false,
Encoding: "console",
OutputPaths: []string{"stderr"},
ErrorOutputPaths: []string{"stderr"},
DisableCaller: false,
DisableStacktrace: false,
InitialFields: map[string]any(nil),
ResourceAsZapFields: false,
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
Loading