diff --git a/CHANGELOG.md b/CHANGELOG.md index cff94fe55d7..a17f343b62c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Add `"go.opentelemetry.io/contrib/config"` package that includes configuration models generated via go-jsonschema. (#4376) - Add `NewSDK` function to `"go.opentelemetry.io/contrib/config"`. The initial implementation only returns noop providers. (#4414) - Add metrics support (No-op, OTLP and Prometheus) to `go.opentelemetry.io/contrib/exporters/autoexport`. (#4229, #4479) +- Add support for standard output exporter via environment variables for the metric and trace signals identified by the key: `console`. () ### Changed diff --git a/exporters/autoexport/go.mod b/exporters/autoexport/go.mod index e2a8b562877..10a6c8bd6c8 100644 --- a/exporters/autoexport/go.mod +++ b/exporters/autoexport/go.mod @@ -12,6 +12,8 @@ require ( go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.19.0 go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0 go.opentelemetry.io/otel/exporters/prometheus v0.42.0 + go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v0.42.0 + go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.19.0 go.opentelemetry.io/otel/sdk v1.19.0 go.opentelemetry.io/otel/sdk/metric v1.19.0 go.uber.org/goleak v1.2.1 diff --git a/exporters/autoexport/go.sum b/exporters/autoexport/go.sum index 47b02887646..0431813cc1e 100644 --- a/exporters/autoexport/go.sum +++ b/exporters/autoexport/go.sum @@ -53,6 +53,10 @@ go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0 h1:IeMey go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0/go.mod h1:oVdCUtjq9MK9BlS7TtucsQwUcXcymNiEDjgDD2jMtZU= go.opentelemetry.io/otel/exporters/prometheus v0.42.0 h1:jwV9iQdvp38fxXi8ZC+lNpxjK16MRcZlpDYvbuO1FiA= go.opentelemetry.io/otel/exporters/prometheus v0.42.0/go.mod h1:f3bYiqNqhoPxkvI2LrXqQVC546K7BuRDL/kKuxkujhA= +go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v0.42.0 h1:4jJuoeOo9W6hZnz+r046fyoH5kykZPRvKfUXJVfMpB0= +go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v0.42.0/go.mod h1:/MtYTE1SfC2QIcE0bDot6fIX+h+WvXjgTqgn9P0LNPE= +go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.19.0 h1:Nw7Dv4lwvGrI68+wULbcq7su9K2cebeCUrDjVrUJHxM= +go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.19.0/go.mod h1:1MsF6Y7gTqosgoZvHlzcaaM8DIMNZgJh87ykokoNH7Y= go.opentelemetry.io/otel/metric v1.19.0 h1:aTzpGtV0ar9wlV4Sna9sdJyII5jTVJEvKETPiOKwvpE= go.opentelemetry.io/otel/metric v1.19.0/go.mod h1:L5rUsV9kM1IxCj1MmSdS+JQAcVm319EUrDVLrt7jqt8= go.opentelemetry.io/otel/sdk v1.19.0 h1:6USY6zH+L8uMH8L3t1enZPR3WFEmSTADlqldyHtJi3o= diff --git a/exporters/autoexport/metrics.go b/exporters/autoexport/metrics.go index d8f260cadd8..d7f4e2f527e 100644 --- a/exporters/autoexport/metrics.go +++ b/exporters/autoexport/metrics.go @@ -30,6 +30,7 @@ import ( "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc" "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp" promexporter "go.opentelemetry.io/otel/exporters/prometheus" + "go.opentelemetry.io/otel/exporters/stdout/stdoutmetric" "go.opentelemetry.io/otel/sdk/metric" ) @@ -49,6 +50,7 @@ func WithFallbackMetricReader(exporter metric.Reader) MetricOption { // - "none" - "no operation" exporter // - "otlp" (default) - OTLP exporter; see [go.opentelemetry.io/otel/exporters/otlp/otlpmetric] // - "prometheus" - Prometheus exporter + HTTP server; see [go.opentelemetry.io/otel/exporters/prometheus] +// - "console" - Standard output exporter; see [https://pkg.go.dev/go.opentelemetry.io/otel/exporters/stdout/stdoutmetric] // // OTEL_EXPORTER_OTLP_PROTOCOL defines OTLP exporter's transport protocol; // supported values: @@ -106,6 +108,13 @@ func init() { return nil, errInvalidOTLPProtocol } }) + RegisterMetricReader("console", func(ctx context.Context) (metric.Reader, error) { + r, err := stdoutmetric.New() + if err != nil { + return nil, err + } + return metric.NewPeriodicReader(r), nil + }) RegisterMetricReader("none", func(ctx context.Context) (metric.Reader, error) { return newNoopMetricReader(), nil }) diff --git a/exporters/autoexport/metrics_test.go b/exporters/autoexport/metrics_test.go index 6624db36ecd..8972c45abbd 100644 --- a/exporters/autoexport/metrics_test.go +++ b/exporters/autoexport/metrics_test.go @@ -40,6 +40,15 @@ func TestMetricExporterNone(t *testing.T) { assert.True(t, IsNoneMetricReader(got)) } +func TestMetricExporterConsole(t *testing.T) { + t.Setenv("OTEL_METRICS_EXPORTER", "console") + got, err := NewMetricReader(context.Background()) + assert.NoError(t, err) + assert.IsType(t, &metric.PeriodicReader{}, got) + exporterType := reflect.Indirect(reflect.ValueOf(got)).FieldByName("exporter").Elem().Type() + assert.Equal(t, "*stdoutmetric.exporter", exporterType.String()) +} + func TestMetricExporterOTLP(t *testing.T) { t.Setenv("OTEL_METRICS_EXPORTER", "otlp") diff --git a/exporters/autoexport/spans.go b/exporters/autoexport/spans.go index e7de52e28a7..69edb3afa87 100644 --- a/exporters/autoexport/spans.go +++ b/exporters/autoexport/spans.go @@ -20,6 +20,7 @@ import ( "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc" "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp" + "go.opentelemetry.io/otel/exporters/stdout/stdouttrace" "go.opentelemetry.io/otel/sdk/trace" ) @@ -43,6 +44,7 @@ func WithFallbackSpanExporter(exporter trace.SpanExporter) SpanOption { // OTEL_TRACES_EXPORTER defines the traces exporter; supported values: // - "none" - "no operation" exporter // - "otlp" (default) - OTLP exporter; see [go.opentelemetry.io/otel/exporters/otlp/otlptrace] +// - "console" - Standard output exporter; see [https://pkg.go.dev/go.opentelemetry.io/otel/exporters/stdout/stdouttrace] // // OTEL_EXPORTER_OTLP_PROTOCOL defines OTLP exporter's transport protocol; // supported values: @@ -88,6 +90,9 @@ func init() { return nil, errInvalidOTLPProtocol } }) + RegisterSpanExporter("console", func(ctx context.Context) (trace.SpanExporter, error) { + return stdouttrace.New() + }) RegisterSpanExporter("none", func(ctx context.Context) (trace.SpanExporter, error) { return noopSpanExporter{}, nil }) diff --git a/exporters/autoexport/spans_test.go b/exporters/autoexport/spans_test.go index b2851549295..1b4de67786a 100644 --- a/exporters/autoexport/spans_test.go +++ b/exporters/autoexport/spans_test.go @@ -21,6 +21,7 @@ import ( "testing" "go.opentelemetry.io/otel/exporters/otlp/otlptrace" + "go.opentelemetry.io/otel/exporters/stdout/stdouttrace" "github.com/stretchr/testify/assert" ) @@ -35,6 +36,13 @@ func TestSpanExporterNone(t *testing.T) { assert.True(t, IsNoneSpanExporter(got)) } +func TestSpanExporterConsole(t *testing.T) { + t.Setenv("OTEL_TRACES_EXPORTER", "console") + got, err := NewSpanExporter(context.Background()) + assert.NoError(t, err) + assert.IsType(t, &stdouttrace.Exporter{}, got) +} + func TestSpanExporterOTLP(t *testing.T) { t.Setenv("OTEL_TRACES_EXPORTER", "otlp")