trace exporter: add new type `file` (#3298)

Co-authored-by: zhaikangqi <794556486@qq.com>
master
kangqi 2 years ago committed by GitHub
parent 032f2419a2
commit e751736516
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -4,6 +4,7 @@ import (
"context" "context"
"fmt" "fmt"
"net/url" "net/url"
"os"
"sync" "sync"
"github.com/zeromicro/go-zero/core/lang" "github.com/zeromicro/go-zero/core/lang"
@ -12,6 +13,7 @@ import (
"go.opentelemetry.io/otel/exporters/jaeger" "go.opentelemetry.io/otel/exporters/jaeger"
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc" "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp" "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp"
"go.opentelemetry.io/otel/exporters/stdout/stdouttrace"
"go.opentelemetry.io/otel/exporters/zipkin" "go.opentelemetry.io/otel/exporters/zipkin"
"go.opentelemetry.io/otel/sdk/resource" "go.opentelemetry.io/otel/sdk/resource"
sdktrace "go.opentelemetry.io/otel/sdk/trace" sdktrace "go.opentelemetry.io/otel/sdk/trace"
@ -23,6 +25,7 @@ const (
kindZipkin = "zipkin" kindZipkin = "zipkin"
kindOtlpGrpc = "otlpgrpc" kindOtlpGrpc = "otlpgrpc"
kindOtlpHttp = "otlphttp" kindOtlpHttp = "otlphttp"
kindFile = "file"
) )
var ( var (
@ -102,6 +105,12 @@ func createExporter(c Config) (sdktrace.SpanExporter, error) {
context.Background(), context.Background(),
opts..., opts...,
) )
case kindFile:
f, err := os.OpenFile(c.Endpoint, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
return nil, fmt.Errorf("file exporter endpoint error: %s", err.Error())
}
return stdouttrace.New(stdouttrace.WithWriter(f))
default: default:
return nil, fmt.Errorf("unknown exporter: %s", c.Batcher) return nil, fmt.Errorf("unknown exporter: %s", c.Batcher)
} }

@ -17,6 +17,7 @@ func TestStartAgent(t *testing.T) {
endpoint4 = "localhost:1236" endpoint4 = "localhost:1236"
endpoint5 = "udp://localhost:6831" endpoint5 = "udp://localhost:6831"
endpoint6 = "localhost:1237" endpoint6 = "localhost:1237"
endpoint7 = "/tmp/trace.log"
) )
c1 := Config{ c1 := Config{
Name: "foo", Name: "foo",
@ -63,6 +64,11 @@ func TestStartAgent(t *testing.T) {
Endpoint: endpoint6, Endpoint: endpoint6,
Batcher: kindJaeger, Batcher: kindJaeger,
} }
c9 := Config{
Name: "file",
Endpoint: endpoint7,
Batcher: kindFile,
}
StartAgent(c1) StartAgent(c1)
StartAgent(c1) StartAgent(c1)
@ -73,13 +79,14 @@ func TestStartAgent(t *testing.T) {
StartAgent(c6) StartAgent(c6)
StartAgent(c7) StartAgent(c7)
StartAgent(c8) StartAgent(c8)
StartAgent(c9)
defer StopAgent() defer StopAgent()
lock.Lock() lock.Lock()
defer lock.Unlock() defer lock.Unlock()
// because remotehost cannot be resolved // because remotehost cannot be resolved
assert.Equal(t, 5, len(agents)) assert.Equal(t, 6, len(agents))
_, ok := agents[""] _, ok := agents[""]
assert.True(t, ok) assert.True(t, ok)
_, ok = agents[endpoint1] _, ok = agents[endpoint1]
@ -90,4 +97,6 @@ func TestStartAgent(t *testing.T) {
assert.True(t, ok) assert.True(t, ok)
_, ok = agents[endpoint6] _, ok = agents[endpoint6]
assert.False(t, ok) assert.False(t, ok)
_, ok = agents[endpoint7]
assert.True(t, ok)
} }

@ -8,7 +8,7 @@ type Config struct {
Name string `json:",optional"` Name string `json:",optional"`
Endpoint string `json:",optional"` Endpoint string `json:",optional"`
Sampler float64 `json:",default=1.0"` Sampler float64 `json:",default=1.0"`
Batcher string `json:",default=jaeger,options=jaeger|zipkin|otlpgrpc|otlphttp"` Batcher string `json:",default=jaeger,options=jaeger|zipkin|otlpgrpc|otlphttp|file"`
// OtlpHeaders represents the headers for OTLP gRPC or HTTP transport. // OtlpHeaders represents the headers for OTLP gRPC or HTTP transport.
// For example: // For example:
// uptrace-dsn: 'http://project2_secret_token@localhost:14317/2' // uptrace-dsn: 'http://project2_secret_token@localhost:14317/2'

@ -27,6 +27,7 @@ require (
go.opentelemetry.io/otel/exporters/jaeger v1.14.0 go.opentelemetry.io/otel/exporters/jaeger v1.14.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.14.0 go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.14.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.14.0 go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.14.0
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.14.0
go.opentelemetry.io/otel/exporters/zipkin v1.14.0 go.opentelemetry.io/otel/exporters/zipkin v1.14.0
go.opentelemetry.io/otel/sdk v1.14.0 go.opentelemetry.io/otel/sdk v1.14.0
go.opentelemetry.io/otel/trace v1.14.0 go.opentelemetry.io/otel/trace v1.14.0

@ -341,6 +341,8 @@ go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.14.0 h1:ap+y8
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.14.0/go.mod h1:5w41DY6S9gZrbjuq6Y+753e96WfPha5IcsOSZTtullM= go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.14.0/go.mod h1:5w41DY6S9gZrbjuq6Y+753e96WfPha5IcsOSZTtullM=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.14.0 h1:3jAYbRHQAqzLjd9I4tzxwJ8Pk/N6AqBcF6m1ZHrxG94= go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.14.0 h1:3jAYbRHQAqzLjd9I4tzxwJ8Pk/N6AqBcF6m1ZHrxG94=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.14.0/go.mod h1:+N7zNjIJv4K+DeX67XXET0P+eIciESgaFDBqh+ZJFS4= go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.14.0/go.mod h1:+N7zNjIJv4K+DeX67XXET0P+eIciESgaFDBqh+ZJFS4=
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.14.0 h1:sEL90JjOO/4yhquXl5zTAkLLsZ5+MycAgX99SDsxGc8=
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.14.0/go.mod h1:oCslUcizYdpKYyS9e8srZEqM6BB8fq41VJBjLAE6z1w=
go.opentelemetry.io/otel/exporters/zipkin v1.14.0 h1:reEVE1upBF9tcujgvSqLJS0SrI7JQPaTKP4s4rymnSs= go.opentelemetry.io/otel/exporters/zipkin v1.14.0 h1:reEVE1upBF9tcujgvSqLJS0SrI7JQPaTKP4s4rymnSs=
go.opentelemetry.io/otel/exporters/zipkin v1.14.0/go.mod h1:RcjvOAcvhzcufQP8aHmzRw1gE9g/VEZufDdo2w+s4sk= go.opentelemetry.io/otel/exporters/zipkin v1.14.0/go.mod h1:RcjvOAcvhzcufQP8aHmzRw1gE9g/VEZufDdo2w+s4sk=
go.opentelemetry.io/otel/sdk v1.14.0 h1:PDCppFRDq8A1jL9v6KMI6dYesaq+DFcDZvjsoGvxGzY= go.opentelemetry.io/otel/sdk v1.14.0 h1:PDCppFRDq8A1jL9v6KMI6dYesaq+DFcDZvjsoGvxGzY=

Loading…
Cancel
Save