Skip to content
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
1 change: 1 addition & 0 deletions packages/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ func NewGinServer(ctx context.Context, config cfg.Config, tel *telemetry.Client,
"sdk_runtime",
"system",
}
corsConfig.AllowHeaders = append(corsConfig.AllowHeaders, telemetry.ContextPropagationHeaders()...)
r.Use(cors.New(corsConfig))

// Create a team API Key auth validator
Expand Down
1 change: 1 addition & 0 deletions packages/dashboard-api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ func run() int {
sharedauth.HeaderSupabaseToken,
sharedauth.HeaderSupabaseTeam,
}
corsConfig.AllowHeaders = append(corsConfig.AllowHeaders, telemetry.ContextPropagationHeaders()...)
r.Use(cors.New(corsConfig))

r.Use(
Expand Down
11 changes: 5 additions & 6 deletions packages/shared/pkg/middleware/otel/tracing/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ import (

"github.com/gin-gonic/gin"
"go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/propagation"
semconv "go.opentelemetry.io/otel/semconv/v1.12.0"
oteltrace "go.opentelemetry.io/otel/trace"

Expand Down Expand Up @@ -73,20 +75,17 @@ func Middleware(tracerProvider oteltrace.TracerProvider, service string) gin.Han

return func(c *gin.Context) {
c.Set(tracerKey, tracer)
ctx := c.Request.Context()
savedCtx := c.Request.Context()
ctx := otel.GetTextMapPropagator().Extract(savedCtx, propagation.HeaderCarrier(c.Request.Header))

// Store the server receive time as the request start time
// This allows us to calculate the whole request duration from server receive to completion
ctx = WithRequestStartTime(ctx, time.Now())

defer func() {
c.Request = c.Request.WithContext(ctx)
c.Request = c.Request.WithContext(savedCtx)
}()

// Remove traceparent (it's coming from our users and it can cause multiple calls share the same trace ID)
if c.Request.Header.Get("traceparent") != "" {
c.Request.Header.Del("traceparent")
}
if edgeTraceID, ok := telemetry.ParseEdgeTraceID(
c.Request.Header.Get(telemetry.GCPTraceContextHeader),
c.Request.Header.Get(telemetry.AWSTraceContextHeader),
Expand Down
6 changes: 6 additions & 0 deletions packages/shared/pkg/telemetry/traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"google.golang.org/grpc/encoding/gzip"
)

var contextPropagationHeaders = NewTextPropagator().Fields()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We won't necessarily be using this one:

Suggested change
var contextPropagationHeaders = NewTextPropagator().Fields()
var contextPropagationHeaders []string
func init() {
contextPropagationHeaders = otel.GetTextMapPropagator().Fields()
}


type noopSpanExporter struct{}

// ExportSpans handles export of spans by dropping them.
Expand Down Expand Up @@ -56,3 +58,7 @@ func NewTracerProvider(spanExporter sdktrace.SpanExporter, res *resource.Resourc
func NewTextPropagator() propagation.TextMapPropagator {
return propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{})
}

func ContextPropagationHeaders() []string {
return append([]string(nil), contextPropagationHeaders...)
}
Loading