mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-23 09:00:20 +08:00
trace exporter: add new type file
(#3298)
Co-authored-by: zhaikangqi <794556486@qq.com>
This commit is contained in:
parent
032f2419a2
commit
e751736516
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/lang"
|
||||
@ -12,6 +13,7 @@ import (
|
||||
"go.opentelemetry.io/otel/exporters/jaeger"
|
||||
"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/exporters/zipkin"
|
||||
"go.opentelemetry.io/otel/sdk/resource"
|
||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
||||
@ -23,6 +25,7 @@ const (
|
||||
kindZipkin = "zipkin"
|
||||
kindOtlpGrpc = "otlpgrpc"
|
||||
kindOtlpHttp = "otlphttp"
|
||||
kindFile = "file"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -102,6 +105,12 @@ func createExporter(c Config) (sdktrace.SpanExporter, error) {
|
||||
context.Background(),
|
||||
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:
|
||||
return nil, fmt.Errorf("unknown exporter: %s", c.Batcher)
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ func TestStartAgent(t *testing.T) {
|
||||
endpoint4 = "localhost:1236"
|
||||
endpoint5 = "udp://localhost:6831"
|
||||
endpoint6 = "localhost:1237"
|
||||
endpoint7 = "/tmp/trace.log"
|
||||
)
|
||||
c1 := Config{
|
||||
Name: "foo",
|
||||
@ -63,6 +64,11 @@ func TestStartAgent(t *testing.T) {
|
||||
Endpoint: endpoint6,
|
||||
Batcher: kindJaeger,
|
||||
}
|
||||
c9 := Config{
|
||||
Name: "file",
|
||||
Endpoint: endpoint7,
|
||||
Batcher: kindFile,
|
||||
}
|
||||
|
||||
StartAgent(c1)
|
||||
StartAgent(c1)
|
||||
@ -73,13 +79,14 @@ func TestStartAgent(t *testing.T) {
|
||||
StartAgent(c6)
|
||||
StartAgent(c7)
|
||||
StartAgent(c8)
|
||||
StartAgent(c9)
|
||||
defer StopAgent()
|
||||
|
||||
lock.Lock()
|
||||
defer lock.Unlock()
|
||||
|
||||
// because remotehost cannot be resolved
|
||||
assert.Equal(t, 5, len(agents))
|
||||
assert.Equal(t, 6, len(agents))
|
||||
_, ok := agents[""]
|
||||
assert.True(t, ok)
|
||||
_, ok = agents[endpoint1]
|
||||
@ -90,4 +97,6 @@ func TestStartAgent(t *testing.T) {
|
||||
assert.True(t, ok)
|
||||
_, ok = agents[endpoint6]
|
||||
assert.False(t, ok)
|
||||
_, ok = agents[endpoint7]
|
||||
assert.True(t, ok)
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ type Config struct {
|
||||
Name string `json:",optional"`
|
||||
Endpoint string `json:",optional"`
|
||||
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.
|
||||
// For example:
|
||||
// uptrace-dsn: 'http://project2_secret_token@localhost:14317/2'
|
||||
|
1
go.mod
1
go.mod
@ -27,6 +27,7 @@ require (
|
||||
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/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/sdk v1.14.0
|
||||
go.opentelemetry.io/otel/trace v1.14.0
|
||||
|
2
go.sum
2
go.sum
@ -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/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/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/go.mod h1:RcjvOAcvhzcufQP8aHmzRw1gE9g/VEZufDdo2w+s4sk=
|
||||
go.opentelemetry.io/otel/sdk v1.14.0 h1:PDCppFRDq8A1jL9v6KMI6dYesaq+DFcDZvjsoGvxGzY=
|
||||
|
Loading…
Reference in New Issue
Block a user