From f44b815969a1a4d9e7024780640f745ec0c50daf Mon Sep 17 00:00:00 2001 From: Rudinei Goi Roecker Date: Tue, 19 Sep 2023 10:34:41 -0300 Subject: [PATCH] feat(tracing): add OTLP headers config --- config/flipt.schema.cue | 1 + config/flipt.schema.json | 4 ++++ internal/cmd/grpc.go | 1 + internal/config/config_test.go | 12 ++++++++++++ internal/config/testdata/tracing/otlp.yml | 7 +++++++ internal/config/tracing.go | 3 ++- 6 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 internal/config/testdata/tracing/otlp.yml diff --git a/config/flipt.schema.cue b/config/flipt.schema.cue index 80f3d5badf..4762cc321b 100644 --- a/config/flipt.schema.cue +++ b/config/flipt.schema.cue @@ -213,6 +213,7 @@ import "strings" otlp?: { endpoint?: string | *"localhost:4317" + headers?: [string]: string } } diff --git a/config/flipt.schema.json b/config/flipt.schema.json index 6753bafc2f..d6d8343a48 100644 --- a/config/flipt.schema.json +++ b/config/flipt.schema.json @@ -619,6 +619,10 @@ "endpoint": { "type": "string", "default": "localhost:4317" + }, + "headers": { + "type": "object", + "additionalProperties": { "type": "string" } } }, "title": "OTLP" diff --git a/internal/cmd/grpc.go b/internal/cmd/grpc.go index 4177e15339..6811dc9ba8 100644 --- a/internal/cmd/grpc.go +++ b/internal/cmd/grpc.go @@ -218,6 +218,7 @@ func NewGRPCServer( // TODO: support additional configuration options client := otlptracegrpc.NewClient( otlptracegrpc.WithEndpoint(cfg.Tracing.OTLP.Endpoint), + otlptracegrpc.WithHeaders(cfg.Tracing.OTLP.Headers), // TODO: support TLS otlptracegrpc.WithInsecure()) exp, err = otlptrace.New(ctx, client) diff --git a/internal/config/config_test.go b/internal/config/config_test.go index aeb5219a04..bd9b4c8c38 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -333,6 +333,18 @@ func TestLoad(t *testing.T) { return cfg }, }, + { + name: "tracing otlp", + path: "./testdata/tracing/otlp.yml", + expected: func() *Config { + cfg := Default() + cfg.Tracing.Enabled = true + cfg.Tracing.Exporter = TracingOTLP + cfg.Tracing.OTLP.Endpoint = "http://localhost:9999" + cfg.Tracing.OTLP.Headers = map[string]string{"api-key": "test-key"} + return cfg + }, + }, { name: "database key/value", path: "./testdata/database.yml", diff --git a/internal/config/testdata/tracing/otlp.yml b/internal/config/testdata/tracing/otlp.yml new file mode 100644 index 0000000000..0aa683bfe0 --- /dev/null +++ b/internal/config/testdata/tracing/otlp.yml @@ -0,0 +1,7 @@ +tracing: + enabled: true + exporter: otlp + otlp: + endpoint: http://localhost:9999 + headers: + api-key: test-key diff --git a/internal/config/tracing.go b/internal/config/tracing.go index 40b2131971..0d012c115d 100644 --- a/internal/config/tracing.go +++ b/internal/config/tracing.go @@ -106,5 +106,6 @@ type ZipkinTracingConfig struct { // OTLPTracingConfig contains fields, which configure // OTLP span and tracing output destination. type OTLPTracingConfig struct { - Endpoint string `json:"endpoint,omitempty" mapstructure:"endpoint"` + Endpoint string `json:"endpoint,omitempty" mapstructure:"endpoint"` + Headers map[string]string `json:"headers,omitempty" mapstructure:"headers"` }