-
-
Notifications
You must be signed in to change notification settings - Fork 338
Expand file tree
/
Copy pathtracer.go
More file actions
26 lines (20 loc) · 811 Bytes
/
tracer.go
File metadata and controls
26 lines (20 loc) · 811 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package mercure
import (
"context"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/trace"
)
const tracerName = "github.com/dunglas/mercure"
// startSpan starts a span using the TracerProvider attached to the active span
// in ctx. When no tracer is active (e.g. Caddy's `tracing` directive is not
// enabled), this falls back to the OpenTelemetry no-op tracer: no exporters,
// no globals touched.
func startSpan(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span) {
tracer := trace.SpanFromContext(ctx).TracerProvider().Tracer(tracerName)
return tracer.Start(ctx, name, opts...)
}
// recordSpanError marks the span as errored.
func recordSpanError(span trace.Span, err error) {
span.RecordError(err)
span.SetStatus(codes.Error, err.Error())
}