Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
ymtdzzz committed Apr 6, 2024
1 parent 8ef5d53 commit 945253b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ service:
receivers: [otlp]
processors: []
exporters: [tui]
logs:
receivers: [otlp]
processors: []
exporters: [tui]
`

provider := yamlprovider.New()
Expand Down
7 changes: 7 additions & 0 deletions tuiexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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() {
Expand Down
23 changes: 22 additions & 1 deletion tuiexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 945253b

Please sign in to comment.