Skip to content

Commit

Permalink
fix: add headers and endpoint to otel
Browse files Browse the repository at this point in the history
  • Loading branch information
kangmingtay committed Jan 17, 2025
1 parent f72f0ee commit d1d21a8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
20 changes: 20 additions & 0 deletions internal/conf/tracing.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package conf

import (
"encoding/json"
"fmt"
)

type TracingExporter = string

const (
Expand All @@ -24,10 +29,25 @@ type TracingConfig struct {
// ServiceName is the service name to use with OpenTracing.
ServiceName string `default:"gotrue" split_words:"true"`

Headers TracingHeaderDecoder

// Tags are the tags to associate with OpenTracing.
Tags map[string]string
}

func (tc *TracingConfig) Validate() error {
return nil
}

type TracingHeaderDecoder map[string]string

func (h *TracingHeaderDecoder) Decode(value string) error {
headers := make(TracingHeaderDecoder)
if value != "" {
if err := json.Unmarshal([]byte(value), &headers); err != nil {
return fmt.Errorf("conf: custom headers not a map[string][]string: %w", err)
}
}
*h = headers
return nil
}
6 changes: 5 additions & 1 deletion internal/observability/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ func enableOpenTelemetryTracing(ctx context.Context, tc *conf.TracingConfig) err

switch tc.ExporterProtocol {
case "grpc":
traceExporter, err = otlptracegrpc.New(ctx)
traceExporter, err = otlptracegrpc.New(
ctx,
otlptracegrpc.WithHeaders(tc.Headers),
otlptracegrpc.WithEndpoint(fmt.Sprintf("%s:%s", tc.Host, tc.Port)),
)
if err != nil {
return err
}
Expand Down

0 comments on commit d1d21a8

Please sign in to comment.