Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] add support for sending headers to tracing system #3604

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/advanced/tracing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
7 changes: 7 additions & 0 deletions docs/configuration/observability.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions docs/locales/zh/advanced/tracing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
5 changes: 5 additions & 0 deletions docs/locales/zh/configuration/observability.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ tracing-transport: "grpc"
# 默认值: ""
tracing-endpoint: ""

# TODO
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: help would be appreciated here for a proper translation.

# 示例: {"Authorization": "Bearer super-secret-token", "Dataset": "gotosocial"}
# 默认值: {}
tracing-headers: {}

# 布尔值。禁用gRPC和HTTP传输协议的TLS。
# 默认值: false
tracing-insecure-transport: false
Expand Down
7 changes: 7 additions & 0 deletions example/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
1 change: 1 addition & 0 deletions internal/config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ var Defaults = Configuration{
TracingEnabled: false,
TracingTransport: "grpc",
TracingEndpoint: "",
TracingHeaders: map[string]string{},
TracingInsecureTransport: false,

MetricsEnabled: false,
Expand Down
25 changes: 25 additions & 0 deletions internal/config/helpers.gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -2200,6 +2200,31 @@ func GetTracingEndpoint() string { return global.GetTracingEndpoint() }
// SetTracingEndpoint safely sets the value for global configuration 'TracingEndpoint' field
func SetTracingEndpoint(v string) { global.SetTracingEndpoint(v) }

// GetTracingHeaders safely fetches the Configuration value for state's 'TracingHeaders' field
func (st *ConfigState) GetTracingHeaders() (v map[string]string) {
joschi marked this conversation as resolved.
Show resolved Hide resolved
st.mutex.RLock()
v = st.config.TracingHeaders
st.mutex.RUnlock()
return
}

// SetTracingHeaders 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()
}

// TracingHeadersFlag returns the flag name for the 'TracingHeaders' field
func TracingHeadersFlag() string { return "tracing-headers" }

// GetTracingHeaders safely fetches the value for global configuration 'TracingHeaders' field
func GetTracingHeaders() map[string]string { return global.GetTracingHeaders() }

// SetTracingHeaders safely sets the value for global configuration 'TracingHeaders' field
func SetTracingHeaders(v map[string]string) { global.SetTracingHeaders(v) }

// GetTracingInsecureTransport safely fetches the Configuration value for state's 'TracingInsecureTransport' field
func (st *ConfigState) GetTracingInsecureTransport() (v bool) {
st.mutex.RLock()
Expand Down
1 change: 1 addition & 0 deletions internal/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func Initialize() error {
case "grpc":
opts := []otlptracegrpc.Option{
otlptracegrpc.WithEndpoint(config.GetTracingEndpoint()),
otlptracegrpc.WithHeaders(config.GetTracingHeaders()),
}
if insecure {
opts = append(opts, otlptracegrpc.WithInsecure())
Expand Down
1 change: 1 addition & 0 deletions test/envparsing.sh
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ EXPECT=$(cat << "EOF"
"tls-certificate-key": "",
"tracing-enabled": false,
"tracing-endpoint": "localhost:4317",
"tracing-headers": {},
"tracing-insecure-transport": true,
"tracing-transport": "grpc",
"trusted-proxies": [
Expand Down