From 53b99aea3498ec571a045ef9e1dd2a220f98ba6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E5=8F=AF?= Date: Mon, 9 Sep 2024 14:35:42 +0800 Subject: [PATCH] feat: add grpc support for log autoexport (#6083) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Robert PajÄ…k --- CHANGELOG.md | 1 + exporters/autoexport/go.mod | 1 + exporters/autoexport/go.sum | 2 ++ exporters/autoexport/logs.go | 8 +++++--- exporters/autoexport/logs_test.go | 2 ++ 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 038445e6c04..16e09533c0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Added - Add `NewProducer` to `go.opentelemetry.io/contrib/instrumentation/runtime`, which allows collecting the `go.schedule.duration` histogram metric from the Go runtime. (#5991) +- Add gRPC protocol support for OTLP log exporter in `go.opentelemetry.io/contrib/exporters/autoexport`. (#6083) ### Removed diff --git a/exporters/autoexport/go.mod b/exporters/autoexport/go.mod index a13cc9ced19..3556a5e74c1 100644 --- a/exporters/autoexport/go.mod +++ b/exporters/autoexport/go.mod @@ -7,6 +7,7 @@ require ( github.com/stretchr/testify v1.9.0 go.opentelemetry.io/contrib/bridges/prometheus v0.54.0 go.opentelemetry.io/otel v1.29.0 + go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.5.0 go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.5.0 go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.29.0 go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.29.0 diff --git a/exporters/autoexport/go.sum b/exporters/autoexport/go.sum index c12aa97b888..1d014ef13ad 100644 --- a/exporters/autoexport/go.sum +++ b/exporters/autoexport/go.sum @@ -43,6 +43,8 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= go.opentelemetry.io/otel v1.29.0 h1:PdomN/Al4q/lN6iBJEN3AwPvUiHPMlt93c8bqTG5Llw= go.opentelemetry.io/otel v1.29.0/go.mod h1:N/WtXPs1CNCUEx+Agz5uouwCba+i+bJGFicT8SR4NP8= +go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.5.0 h1:iWyFL+atC9S1e6MFDLNUZieyKTmsrvsDzuozUDbFg8E= +go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.5.0/go.mod h1:0Ur7rPCJmkHksYcBywsFXnKBG3pqGl4TGltZ+T3qhSA= go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.5.0 h1:4d++HQ+Ihdl+53zSjtsCUFDmNMju2FC9qFkUlTxPLqo= go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.5.0/go.mod h1:mQX5dTO3Mh5ZF7bPKDkt5c/7C41u/SiDr9XgTpzXXn8= go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.29.0 h1:k6fQVDQexDE+3jG2SfCQjnHS7OamcP73YMoxEVq5B6k= diff --git a/exporters/autoexport/logs.go b/exporters/autoexport/logs.go index 9e926ce32e1..618379c621d 100644 --- a/exporters/autoexport/logs.go +++ b/exporters/autoexport/logs.go @@ -7,6 +7,7 @@ import ( "context" "os" + "go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc" "go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp" "go.opentelemetry.io/otel/exporters/stdout/stdoutlog" "go.opentelemetry.io/otel/sdk/log" @@ -31,6 +32,8 @@ var logsSignal = newSignal[log.Exporter]("OTEL_LOGS_EXPORTER") // supported values: // - "http/protobuf" (default) - protobuf-encoded data over HTTP connection; // see: [go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp] +// - "grpc" - gRPC with protobuf-encoded data over HTTP/2 connection; +// see: [go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc] // // OTEL_EXPORTER_OTLP_LOGS_PROTOCOL defines OTLP exporter's transport protocol for the logs signal; // supported values are the same as OTEL_EXPORTER_OTLP_PROTOCOL. @@ -67,9 +70,8 @@ func init() { } switch proto { - // grpc is not supported yet, should comment out when it is supported - // case "grpc": - // return otlploggrpc.New(ctx) + case "grpc": + return otlploggrpc.New(ctx) case "http/protobuf": return otlploghttp.New(ctx) default: diff --git a/exporters/autoexport/logs_test.go b/exporters/autoexport/logs_test.go index 8b6c2a5a686..abf8a09bd30 100644 --- a/exporters/autoexport/logs_test.go +++ b/exporters/autoexport/logs_test.go @@ -41,6 +41,7 @@ func TestLogExporterOTLP(t *testing.T) { protocol, clientType string }{ {"http/protobuf", "atomic.Pointer[go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp.client]"}, + {"grpc", "otlploggrpc.logClient"}, {"", "atomic.Pointer[go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp.client]"}, } { t.Run(fmt.Sprintf("protocol=%q", tc.protocol), func(t *testing.T) { @@ -67,6 +68,7 @@ func TestLogExporterOTLPWithDedicatedProtocol(t *testing.T) { protocol, clientType string }{ {"http/protobuf", "atomic.Pointer[go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp.client]"}, + {"grpc", "otlploggrpc.logClient"}, {"", "atomic.Pointer[go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp.client]"}, } { t.Run(fmt.Sprintf("protocol=%q", tc.protocol), func(t *testing.T) {