diff --git a/docs/advanced/tracing.md b/docs/advanced/tracing.md index c06b449c3..801930d7c 100644 --- a/docs/advanced/tracing.md +++ b/docs/advanced/tracing.md @@ -12,6 +12,9 @@ You'll need the files in [`example/tracing`][ext]. Once you have those you can r tracing-enabled: true tracing-transport: "grpc" tracing-endpoint: "localhost:4317" +tracing-headers: + "Authorization": "Bearer super-secret-token" + "Dataset": "gotosocial" tracing-insecure-transport: true ``` diff --git a/docs/configuration/observability.md b/docs/configuration/observability.md index 0fcf4710e..1e3718fac 100644 --- a/docs/configuration/observability.md +++ b/docs/configuration/observability.md @@ -35,6 +35,13 @@ tracing-transport: "grpc" # Default: "" tracing-endpoint: "" +# Map of strings. Additional headers to send to the trace ingester. +# Additional HTTP or gRPC headers can be used for authentication or other additional +# information for the tracing system. +# Examples: {"Authorization": "Bearer super-secret-token", "Dataset": "gotosocial"} +# Default: {} +tracing-headers: {} + # Bool. Disable TLS for the gRPC and HTTP transport protocols. # Default: false tracing-insecure-transport: false diff --git a/docs/locales/zh/advanced/tracing.md b/docs/locales/zh/advanced/tracing.md index dc502b9e4..50a5c3f23 100644 --- a/docs/locales/zh/advanced/tracing.md +++ b/docs/locales/zh/advanced/tracing.md @@ -12,6 +12,9 @@ GoToSocial 内置了基于 [OpenTelemetry][otel] 的追踪功能。虽然并没 tracing-enabled: true tracing-transport: "grpc" tracing-endpoint: "localhost:4317" +tracing-headers: + "Authorization": "Bearer super-secret-token" + "Dataset": "gotosocial" tracing-insecure-transport: true ``` diff --git a/docs/locales/zh/configuration/observability.md b/docs/locales/zh/configuration/observability.md index c26b2b351..743ee9102 100644 --- a/docs/locales/zh/configuration/observability.md +++ b/docs/locales/zh/configuration/observability.md @@ -31,6 +31,11 @@ tracing-transport: "grpc" # 默认值: "" tracing-endpoint: "" +# TODO +# 示例: {"Authorization": "Bearer super-secret-token", "Dataset": "gotosocial"} +# 默认值: {} +tracing-headers: {} + # 布尔值。禁用gRPC和HTTP传输协议的TLS。 # 默认值: false tracing-insecure-transport: false diff --git a/example/config.yaml b/example/config.yaml index 644b51575..7a3742671 100644 --- a/example/config.yaml +++ b/example/config.yaml @@ -928,6 +928,13 @@ tracing-transport: "grpc" # Default: "" tracing-endpoint: "" +# Map of strings. Additional headers to send to the trace ingester. +# Additional HTTP or gRPC headers can be used for authentication or other additional +# information for the tracing system. +# Examples: {"Authorization": "Bearer super-secret-token", "Dataset": "gotosocial"} +# Default: {} +tracing-headers: {} + # Bool. Disable TLS for the gRPC and HTTP transport protocols. # Default: false tracing-insecure-transport: false diff --git a/internal/config/config.go b/internal/config/config.go index 413743409..ee950526a 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -140,10 +140,11 @@ type Configuration struct { OIDCAllowedGroups []string `name:"oidc-allowed-groups" usage:"Membership of one of the listed groups allows access to GtS. If this is empty, all groups are allowed."` OIDCAdminGroups []string `name:"oidc-admin-groups" usage:"Membership of one of the listed groups makes someone a GtS admin"` - TracingEnabled bool `name:"tracing-enabled" usage:"Enable OTLP Tracing"` - TracingTransport string `name:"tracing-transport" usage:"grpc or http"` - TracingEndpoint string `name:"tracing-endpoint" usage:"Endpoint of your trace collector. Eg., 'localhost:4317' for gRPC, 'localhost:4318' for http"` - TracingInsecureTransport bool `name:"tracing-insecure-transport" usage:"Disable TLS for the gRPC or HTTP transport protocol"` + TracingEnabled bool `name:"tracing-enabled" usage:"Enable OTLP Tracing"` + TracingTransport string `name:"tracing-transport" usage:"grpc or http"` + TracingEndpoint string `name:"tracing-endpoint" usage:"Endpoint of your trace collector. Eg., 'localhost:4317' for gRPC, 'localhost:4318' for http"` + TracingHeaders map[string]string `name:"tracing-headers" usage:"Headers for your trace collector. Eg., 'Authorization: Bearer super-secret-token' for sending an 'Authorization' header"` + TracingInsecureTransport bool `name:"tracing-insecure-transport" usage:"Disable TLS for the gRPC or HTTP transport protocol"` MetricsEnabled bool `name:"metrics-enabled" usage:"Enable OpenTelemetry based metrics support."` MetricsAuthEnabled bool `name:"metrics-auth-enabled" usage:"Enable HTTP Basic Authentication for Prometheus metrics endpoint"` diff --git a/internal/config/defaults.go b/internal/config/defaults.go index f77c5c456..54ea3392b 100644 --- a/internal/config/defaults.go +++ b/internal/config/defaults.go @@ -120,6 +120,7 @@ TracingEnabled: false, TracingTransport: "grpc", TracingEndpoint: "", + TracingHeaders: map[string]string{}, TracingInsecureTransport: false, MetricsEnabled: false, diff --git a/internal/config/helpers.gen.go b/internal/config/helpers.gen.go index 543292ebe..dad23cf00 100644 --- a/internal/config/helpers.gen.go +++ b/internal/config/helpers.gen.go @@ -2191,6 +2191,22 @@ func (st *ConfigState) SetTracingEndpoint(v string) { st.reloadToViper() } +// GetTracingHeaders safely fetches the Configuration value for state's 'TracingHeaders' field +func (st *ConfigState) GetTracingHeaders() (v map[string]string) { + st.mutex.RLock() + v = st.config.TracingHeaders + st.mutex.RUnlock() + return +} + +// SetTracingEndpoint safely sets the Configuration value for state's 'TracingHeaders' field +func (st *ConfigState) SetTracingHeaders(v map[string]string) { + st.mutex.Lock() + defer st.mutex.Unlock() + st.config.TracingHeaders = v + st.reloadToViper() +} + // TracingEndpointFlag returns the flag name for the 'TracingEndpoint' field func TracingEndpointFlag() string { return "tracing-endpoint" } diff --git a/internal/tracing/tracing.go b/internal/tracing/tracing.go index dd1e19be9..ee25e43c7 100644 --- a/internal/tracing/tracing.go +++ b/internal/tracing/tracing.go @@ -60,6 +60,7 @@ func Initialize() error { case "grpc": opts := []otlptracegrpc.Option{ otlptracegrpc.WithEndpoint(config.GetTracingEndpoint()), + otlptracegrpc.WithHeaders(config.NewState().GetTracingHeaders()), } if insecure { opts = append(opts, otlptracegrpc.WithInsecure())