mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2024-12-26 21:05:00 +02:00
Add config and doc for stdoutlog exporter (#5158)
This commit is contained in:
parent
98d961b141
commit
d65da34984
9
.github/dependabot.yml
vendored
9
.github/dependabot.yml
vendored
@ -190,6 +190,15 @@ updates:
|
||||
schedule:
|
||||
interval: weekly
|
||||
day: sunday
|
||||
- package-ecosystem: gomod
|
||||
directory: /exporters/stdout/stdoutlog
|
||||
labels:
|
||||
- dependencies
|
||||
- go
|
||||
- Skip Changelog
|
||||
schedule:
|
||||
interval: weekly
|
||||
day: sunday
|
||||
- package-ecosystem: gomod
|
||||
directory: /exporters/stdout/stdoutmetric
|
||||
labels:
|
||||
|
3
exporters/stdout/stdoutlog/README.md
Normal file
3
exporters/stdout/stdoutlog/README.md
Normal file
@ -0,0 +1,3 @@
|
||||
# STDOUT Log Exporter
|
||||
|
||||
[![PkgGoDev](https://pkg.go.dev/badge/go.opentelemetry.io/otel/exporters/stdout/stdoutlog)](https://pkg.go.dev/go.opentelemetry.io/otel/exporters/stdout/stdoutlog)
|
85
exporters/stdout/stdoutlog/config.go
Normal file
85
exporters/stdout/stdoutlog/config.go
Normal file
@ -0,0 +1,85 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package stdoutlog // import "go.opentelemetry.io/otel/exporters/stdout/stdoutlog"
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
var (
|
||||
defaultWriter = os.Stdout
|
||||
defaultPrettyPrint = false
|
||||
defaultTimestamps = true
|
||||
)
|
||||
|
||||
// config contains options for the STDOUT exporter.
|
||||
type config struct {
|
||||
// Writer is the destination. If not set, os.Stdout is used.
|
||||
Writer io.Writer
|
||||
|
||||
// PrettyPrint will encode the output into readable JSON. Default is
|
||||
// false.
|
||||
PrettyPrint bool
|
||||
|
||||
// Timestamps specifies if timestamps should be printed. Default is
|
||||
// true.
|
||||
Timestamps bool
|
||||
}
|
||||
|
||||
// newConfig creates a validated Config configured with options.
|
||||
func newConfig(options []Option) config {
|
||||
cfg := config{
|
||||
Writer: defaultWriter,
|
||||
PrettyPrint: defaultPrettyPrint,
|
||||
Timestamps: defaultTimestamps,
|
||||
}
|
||||
for _, opt := range options {
|
||||
cfg = opt.apply(cfg)
|
||||
}
|
||||
return cfg
|
||||
}
|
||||
|
||||
// Option sets the configuration value for an Exporter.
|
||||
type Option interface {
|
||||
apply(config) config
|
||||
}
|
||||
|
||||
// WithWriter sets the export stream destination.
|
||||
func WithWriter(w io.Writer) Option {
|
||||
return writerOption{w}
|
||||
}
|
||||
|
||||
type writerOption struct {
|
||||
W io.Writer
|
||||
}
|
||||
|
||||
func (o writerOption) apply(cfg config) config {
|
||||
cfg.Writer = o.W
|
||||
return cfg
|
||||
}
|
||||
|
||||
// WithPrettyPrint prettifies the emitted output.
|
||||
func WithPrettyPrint() Option {
|
||||
return prettyPrintOption(true)
|
||||
}
|
||||
|
||||
type prettyPrintOption bool
|
||||
|
||||
func (o prettyPrintOption) apply(cfg config) config {
|
||||
cfg.PrettyPrint = bool(o)
|
||||
return cfg
|
||||
}
|
||||
|
||||
// WithoutTimestamps sets the export stream to not include timestamps.
|
||||
func WithoutTimestamps() Option {
|
||||
return timestampsOption(false)
|
||||
}
|
||||
|
||||
type timestampsOption bool
|
||||
|
||||
func (o timestampsOption) apply(cfg config) config {
|
||||
cfg.Timestamps = bool(o)
|
||||
return cfg
|
||||
}
|
62
exporters/stdout/stdoutlog/config_test.go
Normal file
62
exporters/stdout/stdoutlog/config_test.go
Normal file
@ -0,0 +1,62 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package stdoutlog // import "go.opentelemetry.io/otel/exporters/stdout/stdoutlog"
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewConfig(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
options []Option
|
||||
expected config
|
||||
}{
|
||||
{
|
||||
name: "default",
|
||||
expected: config{
|
||||
Writer: os.Stdout,
|
||||
PrettyPrint: false,
|
||||
Timestamps: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "WithWriter",
|
||||
options: []Option{WithWriter(os.Stderr)},
|
||||
expected: config{
|
||||
Writer: os.Stderr,
|
||||
PrettyPrint: false,
|
||||
Timestamps: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "WithPrettyPrint",
|
||||
options: []Option{WithPrettyPrint()},
|
||||
expected: config{
|
||||
Writer: os.Stdout,
|
||||
PrettyPrint: true,
|
||||
Timestamps: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "WithoutTimestamps",
|
||||
options: []Option{WithoutTimestamps()},
|
||||
expected: config{
|
||||
Writer: os.Stdout,
|
||||
PrettyPrint: false,
|
||||
Timestamps: false,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
cfg := newConfig(tc.options)
|
||||
assert.Equal(t, tc.expected, cfg)
|
||||
})
|
||||
}
|
||||
}
|
12
exporters/stdout/stdoutlog/doc.go
Normal file
12
exporters/stdout/stdoutlog/doc.go
Normal file
@ -0,0 +1,12 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Package stdoutlog provides an exporter for OpenTelemetry log
|
||||
// telemetry.
|
||||
//
|
||||
// The exporter is intended to be used for testing and debugging, it is not
|
||||
// meant for production use. Additionally, it does not provide an interchange
|
||||
// format for OpenTelemetry that is supported with any stability or
|
||||
// compatibility guarantees. If these are needed features, please use the OTLP
|
||||
// exporter instead.
|
||||
package stdoutlog // import "go.opentelemetry.io/otel/exporters/stdout/stdoutlog"
|
11
exporters/stdout/stdoutlog/go.mod
Normal file
11
exporters/stdout/stdoutlog/go.mod
Normal file
@ -0,0 +1,11 @@
|
||||
module go.opentelemetry.io/otel/exporters/stdout/stdoutlog
|
||||
|
||||
go 1.21
|
||||
|
||||
require github.com/stretchr/testify v1.9.0
|
||||
|
||||
require (
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
10
exporters/stdout/stdoutlog/go.sum
Normal file
10
exporters/stdout/stdoutlog/go.sum
Normal file
@ -0,0 +1,10 @@
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
@ -45,3 +45,4 @@ excluded-modules:
|
||||
- go.opentelemetry.io/otel/internal/tools
|
||||
- go.opentelemetry.io/otel/sdk/log
|
||||
- go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp
|
||||
- go.opentelemetry.io/otel/exporters/stdout/stdoutlog
|
||||
|
Loading…
Reference in New Issue
Block a user