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

[exporter/logging] Build exporter's logger from service's logger #5677

Merged
Merged
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
Next Next commit
[exporter/logging] Create logging exporter logger from service logger
  • Loading branch information
mx-psi committed Jul 13, 2022
commit 066c5676911f2e75a0d41ce80cf9175ba8694859
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Add `linux-ppc64le` architecture to cross build tests in CI
- `client`: perform case insensitive lookups in case the requested metadata value isn't found (#5646)
- `loggingexporter`: Decouple `loglevel` field from level of logged messages (#5678)
- `loggingexporter`: create the exporter's logger from the service's logger (#5677)

### 🧰 Bug fixes 🧰

Expand Down
44 changes: 12 additions & 32 deletions exporter/loggingexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package loggingexporter // import "go.opentelemetry.io/collector/exporter/loggin

import (
"context"
"time"

"go.uber.org/zap"
"go.uber.org/zap/zapcore"
Expand Down Expand Up @@ -53,50 +54,29 @@ func createDefaultConfig() config.Exporter {

func createTracesExporter(_ context.Context, set component.ExporterCreateSettings, config config.Exporter) (component.TracesExporter, error) {
cfg := config.(*Config)

exporterLogger, err := createLogger(cfg)
if err != nil {
return nil, err
}

exporterLogger := createLogger(cfg, set.TelemetrySettings.Logger)
return newTracesExporter(cfg, exporterLogger, set)
}

func createMetricsExporter(_ context.Context, set component.ExporterCreateSettings, config config.Exporter) (component.MetricsExporter, error) {
cfg := config.(*Config)

exporterLogger, err := createLogger(cfg)
if err != nil {
return nil, err
}

exporterLogger := createLogger(cfg, set.TelemetrySettings.Logger)
return newMetricsExporter(cfg, exporterLogger, set)
}

func createLogsExporter(_ context.Context, set component.ExporterCreateSettings, config config.Exporter) (component.LogsExporter, error) {
cfg := config.(*Config)

exporterLogger, err := createLogger(cfg)
if err != nil {
return nil, err
}

exporterLogger := createLogger(cfg, set.TelemetrySettings.Logger)
return newLogsExporter(cfg, exporterLogger, set)
}

func createLogger(cfg *Config) (*zap.Logger, error) {
// We take development config as the base since it matches the purpose
// of logging exporter being used for debugging reasons (so e.g. console encoder)
conf := zap.NewDevelopmentConfig()
conf.Level = zap.NewAtomicLevelAt(cfg.LogLevel)
conf.Sampling = &zap.SamplingConfig{
Initial: cfg.SamplingInitial,
Thereafter: cfg.SamplingThereafter,
}
func createLogger(cfg *Config, logger *zap.Logger) *zap.Logger {
core := zapcore.NewSamplerWithOptions(
tigrannajaryan marked this conversation as resolved.
Show resolved Hide resolved
logger.Core(),
1*time.Second,
cfg.SamplingInitial,
cfg.SamplingThereafter,
)

logginglogger, err := conf.Build()
if err != nil {
return nil, err
}
return logginglogger, nil
return zap.New(core)
}