Skip to content

Commit

Permalink
config: Implement stdoutlog exporter (#5850)
Browse files Browse the repository at this point in the history
Depends on #5849

Closes #5432

---------

Co-authored-by: Damien Mathieu <[email protected]>
  • Loading branch information
robinknaapen and dmathieu authored Jul 5, 2024
1 parent cd25591 commit c1f2786
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
### Added

- Add the new `go.opentelemetry.io/contrib/instrgen` package to provide auto-generated source code instrumentation. (#3068, #3108)
- Support for stdoutlog exporter in `go.opentelemetry.io/contrib/config`. (#5850)

## [1.28.0/0.53.0/0.22.0/0.8.0/0.3.0/0.1.0] - 2024-07-02

Expand Down
1 change: 1 addition & 0 deletions config/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.28.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.28.0
go.opentelemetry.io/otel/exporters/prometheus v0.50.0
go.opentelemetry.io/otel/exporters/stdout/stdoutlog v0.4.0
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.28.0
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.28.0
go.opentelemetry.io/otel/log v0.4.0
Expand Down
2 changes: 2 additions & 0 deletions config/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.28.0 h1:j9+03
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.28.0/go.mod h1:Y5+XiUG4Emn1hTfciPzGPJaSI+RpDts6BnCIir0SLqk=
go.opentelemetry.io/otel/exporters/prometheus v0.50.0 h1:2Ewsda6hejmbhGFyUvWZjUThC98Cf8Zy6g0zkIimOng=
go.opentelemetry.io/otel/exporters/prometheus v0.50.0/go.mod h1:pMm5PkUo5YwbLiuEf7t2xg4wbP0/eSJrMxIMxKosynY=
go.opentelemetry.io/otel/exporters/stdout/stdoutlog v0.4.0 h1:0MH3f8lZrflbUWXVxyBg/zviDFdGE062uKh5+fu8Vv0=
go.opentelemetry.io/otel/exporters/stdout/stdoutlog v0.4.0/go.mod h1:Vh68vYiHY5mPdekTr0ox0sALsqjoVy0w3Os278yX5SQ=
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.28.0 h1:BJee2iLkfRfl9lc7aFmBwkWxY/RI1RDdXepSF6y8TPE=
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.28.0/go.mod h1:DIzlHs3DRscCIBU3Y9YSzPfScwnYnzfnCd4g8zA7bZc=
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.28.0 h1:EVSnY9JbEEW92bEkIYOVMw4q1WJxIAGoFTrtYOzWuRQ=
Expand Down
11 changes: 11 additions & 0 deletions config/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

"go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp"
"go.opentelemetry.io/otel/exporters/stdout/stdoutlog"
"go.opentelemetry.io/otel/log"
"go.opentelemetry.io/otel/log/noop"
sdklog "go.opentelemetry.io/otel/sdk/log"
Expand Down Expand Up @@ -64,6 +65,16 @@ func logProcessor(ctx context.Context, processor LogRecordProcessor) (sdklog.Pro
}

func logExporter(ctx context.Context, exporter LogRecordExporter) (sdklog.Exporter, error) {
if exporter.Console != nil && exporter.OTLP != nil {
return nil, errors.New("must not specify multiple exporters")
}

if exporter.Console != nil {
return stdoutlog.New(
stdoutlog.WithPrettyPrint(),
)
}

if exporter.OTLP != nil {
switch exporter.OTLP.Protocol {
case protocolProtobufHTTP:
Expand Down
34 changes: 34 additions & 0 deletions config/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/stretchr/testify/require"

"go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp"
"go.opentelemetry.io/otel/exporters/stdout/stdoutlog"
"go.opentelemetry.io/otel/log"
"go.opentelemetry.io/otel/log/noop"
sdklog "go.opentelemetry.io/otel/sdk/log"
Expand Down Expand Up @@ -59,8 +60,15 @@ func TestLoggerProvider(t *testing.T) {

func TestLogProcessor(t *testing.T) {
ctx := context.Background()

otlpHTTPExporter, err := otlploghttp.New(ctx)
require.NoError(t, err)

consoleExporter, err := stdoutlog.New(
stdoutlog.WithPrettyPrint(),
)
require.NoError(t, err)

testCases := []struct {
name string
processor LogRecordProcessor
Expand Down Expand Up @@ -149,6 +157,21 @@ func TestLogProcessor(t *testing.T) {
},
wantErr: errors.New("no valid log exporter"),
},
{
name: "batch/console",
processor: LogRecordProcessor{
Batch: &BatchLogRecordProcessor{
MaxExportBatchSize: ptr(0),
ExportTimeout: ptr(0),
MaxQueueSize: ptr(0),
ScheduleDelay: ptr(0),
Exporter: LogRecordExporter{
Console: map[string]any{},
},
},
},
wantProcessor: sdklog.NewBatchProcessor(consoleExporter),
},
{
name: "batch/otlp-http-exporter",
processor: LogRecordProcessor{
Expand Down Expand Up @@ -341,6 +364,17 @@ func TestLogProcessor(t *testing.T) {
},
wantErr: errors.New("no valid log exporter"),
},
{
name: "simple/console",
processor: LogRecordProcessor{
Simple: &SimpleLogRecordProcessor{
Exporter: LogRecordExporter{
Console: map[string]any{},
},
},
},
wantProcessor: sdklog.NewSimpleProcessor(consoleExporter),
},
{
name: "simple/otlp-exporter",
processor: LogRecordProcessor{
Expand Down

0 comments on commit c1f2786

Please sign in to comment.