31 lines
991 B
Go
31 lines
991 B
Go
package nats
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
|
|
"github.com/samcharles93/archie-core/internal/buildinfo"
|
|
"github.com/samcharles93/archie-core/internal/infrastructure/spanrelay"
|
|
"github.com/samcharles93/archie-core/internal/infrastructure/telemetry"
|
|
"github.com/samcharles93/archie-core/internal/taskrun"
|
|
)
|
|
|
|
// startTracing installs the container's tracer provider on the first request
|
|
// that carries a trace context, which is how the daemon says tracing is on.
|
|
// Spans leave through the daemon, since the container has no route to a
|
|
// collector.
|
|
func (t *Transport) startTracing(ctx context.Context, request taskrun.Request, log *slog.Logger) {
|
|
if len(request.Trace) == 0 {
|
|
return
|
|
}
|
|
t.tracingOnce.Do(func() {
|
|
client := spanrelay.NewExporter(t.conn, request.Task.ID)
|
|
stop, err := telemetry.StartWithClient(ctx, client, 1, "agent", buildinfo.Version)
|
|
if err != nil {
|
|
log.WarnContext(ctx, "container tracing disabled", "err", err)
|
|
return
|
|
}
|
|
t.stopTracing = stop
|
|
})
|
|
}
|