From 945253b753951371218228d56aa11794145802a5 Mon Sep 17 00:00:00 2001 From: "Y.Matsuda" Date: Sat, 6 Apr 2024 22:46:29 +0900 Subject: [PATCH] tmp --- main.go | 4 ++++ tuiexporter/exporter.go | 7 +++++++ tuiexporter/factory.go | 23 ++++++++++++++++++++++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 5fb9836..adc4739 100644 --- a/main.go +++ b/main.go @@ -62,6 +62,10 @@ service: receivers: [otlp] processors: [] exporters: [tui] + logs: + receivers: [otlp] + processors: [] + exporters: [tui] ` provider := yamlprovider.New() diff --git a/tuiexporter/exporter.go b/tuiexporter/exporter.go index f52b4ca..cc88de8 100644 --- a/tuiexporter/exporter.go +++ b/tuiexporter/exporter.go @@ -3,10 +3,12 @@ package tuiexporter import ( "context" "fmt" + "log" "github.com/ymtdzzz/otel-tui/tuiexporter/internal/telemetry" "github.com/ymtdzzz/otel-tui/tuiexporter/internal/tui" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/pdata/plog" "go.opentelemetry.io/collector/pdata/ptrace" ) @@ -26,6 +28,11 @@ func (e *tuiExporter) pushTraces(_ context.Context, traces ptrace.Traces) error return nil } +func (e *tuiExporter) pushLogs(_ context.Context, logs plog.Logs) error { + log.Printf("received log: %+v", logs) + return nil +} + // Start runs the TUI exporter func (e *tuiExporter) Start(_ context.Context, _ component.Host) error { go func() { diff --git a/tuiexporter/factory.go b/tuiexporter/factory.go index ed2facc..51c7960 100644 --- a/tuiexporter/factory.go +++ b/tuiexporter/factory.go @@ -20,7 +20,7 @@ func NewFactory() exporter.Factory { createDefaultConfig, exporter.WithTraces(createTraces, stability), //exporter.WithMetrics(createMetrics, stability), - //exporter.WithLogs(createLog, stability), + exporter.WithLogs(createLogs, stability), ) } @@ -49,6 +49,27 @@ func createTraces(ctx context.Context, set exporter.CreateSettings, cfg componen ) } +func createLogs(ctx context.Context, set exporter.CreateSettings, cfg component.Config) (exporter.Logs, error) { + oCfg := cfg.(*Config) + + e, err := exporters.LoadOrStore( + oCfg, + func() (*tuiExporter, error) { + return newTuiExporter(oCfg), nil + }, + &set.TelemetrySettings, + ) + if err != nil { + return nil, err + } + + return exporterhelper.NewLogsExporter(ctx, set, oCfg, + e.Unwrap().pushLogs, + exporterhelper.WithStart(e.Start), + exporterhelper.WithShutdown(e.Shutdown), + ) +} + // This is the map of already created OTLP receivers for particular configurations. // We maintain this map because the Factory is asked trace and metric receivers separately // when it gets CreateTracesReceiver() and CreateMetricsReceiver() but they must not