Documentation
¶
Index ¶
- Constants
- Variables
- func AddEvent(ctx context.Context, name string, keyvals ...string)
- func Client(ctx context.Context, t http.RoundTripper) http.RoundTripper
- func Context(ctx context.Context, svc string, opts ...TraceOption) (context.Context, error)
- func EndSpan(ctx context.Context)
- func Fail(ctx context.Context, msg string)
- func HTTP(ctx context.Context) func(http.Handler) http.Handler
- func IsTraced(ctx context.Context) bool
- func Log(ctx context.Context) (kvs []log.KV)
- func RecordError(ctx context.Context, err error)
- func SetSpanAttributes(ctx context.Context, keyvals ...string)
- func SpanID(ctx context.Context) string
- func StartSpan(ctx context.Context, name string, keyvals ...string) context.Context
- func StreamClientInterceptor(traceCtx context.Context) grpc.StreamClientInterceptor
- func StreamServerInterceptor(traceCtx context.Context) grpc.StreamServerInterceptor
- func Succeed(ctx context.Context)
- func TraceID(ctx context.Context) string
- func TraceProvider(ctx context.Context) trace.TracerProvider
- func UnaryClientInterceptor(traceCtx context.Context) grpc.UnaryClientInterceptor
- func UnaryServerInterceptor(traceCtx context.Context) grpc.UnaryServerInterceptor
- type TraceOption
Constants ¶
const ( // InstrumentationLibraryName is the name of the instrumentation library. InstrumentationLibraryName = "goa.design/clue" // AttributeRequestID is the name of the span attribute that contains the // request ID. AttributeRequestID = "request.id" )
Variables ¶
var ( // TraceIDLogKey is the key used to log the trace ID. TraceIDLogKey = "traceID" // SpanIDLogKey is the key used to log the span ID. SpanIDLogKey = "spanID" )
Functions ¶
func AddEvent ¶
AddEvent records an event with the given name and attributes in the current span if any.
func Client ¶
func Client(ctx context.Context, t http.RoundTripper) http.RoundTripper
Client returns a roundtripper that wraps t and creates spans for each request. It panics if the context hasn't been initialized with Context.
func HTTP ¶
HTTP returns a tracing middleware that uses a parent based sampler (i.e. traces if the parent request traces) and an adaptive root sampler (i.e. when there is no parent uses a target number of requests per second to trace). The implementation leverages the OpenTelemetry SDK and can thus be configured to send traces to an OpenTelemetry remote collector. It is aware of the Goa RequestID middleware and will use it to propagate the request ID to the trace. HTTP panics if the context hasn't been initialized with Context.
Example:
// Connect to remote trace collector. conn, err := grpc.DialContext(ctx, collectorAddr, grpc.WithTransportCrendentials(insecure.Credentials())) if err != nil { log.Error(ctx, err) os.Exit(1) } // Initialize context for tracing ctx := trace.Context(ctx, svcgen.ServiceName, trace.WithGRPCExporter(conn)) // Mount middleware handler := trace.HTTP(ctx)(mux)
func Log ¶ added in v0.1.0
Log is a log key/value pair generator function that can be used to log trace and span IDs. Example:
ctx := log.Context(ctx, WithFunc(trace.Log)) log.Printf(ctx, "message") Output: traceID=<trace-id> spanID=<span-id> message
func RecordError ¶
RecordError records err as an exception span event for the current span if any. An additional call to SetStatus is required if the Status of the Span should be set to Error, as this method does not change the Span status.
func SetSpanAttributes ¶
SetSpanAttributes adds the given attributes to the current span if any. keyvals must be a list of alternating keys and values. It overwrites any existing attributes with the same key.
func StartSpan ¶
StartSpan starts a new span with the given name and attributes and stores it in the returned context if the request is traced, does nothing otherwise. keyvals must be a list of alternating keys and values.
func StreamClientInterceptor ¶
func StreamClientInterceptor(traceCtx context.Context) grpc.StreamClientInterceptor
StreamClientInterceptor returns an OpenTelemetry StreamClientInterceptor configured to export traces to AWS X-Ray. It panics if the context has not been initialized with Context.
func StreamServerInterceptor ¶
func StreamServerInterceptor(traceCtx context.Context) grpc.StreamServerInterceptor
StreamServerInterceptor returns an OpenTelemetry StreamServerInterceptor configured to export traces to AWS X-Ray. It panics if the context has not been initialized with Context.
func TraceProvider ¶ added in v0.5.0
func TraceProvider(ctx context.Context) trace.TracerProvider
TraceProvider returns the underlying otel trace provider.
func UnaryClientInterceptor ¶
func UnaryClientInterceptor(traceCtx context.Context) grpc.UnaryClientInterceptor
UnaryClientInterceptor returns an OpenTelemetry UnaryClientInterceptor configured to export traces to AWS X-Ray. It panics if the context has not been initialized with Context.
func UnaryServerInterceptor ¶
func UnaryServerInterceptor(traceCtx context.Context) grpc.UnaryServerInterceptor
UnaryServerInterceptor returns an OpenTelemetry UnaryServerInterceptor configured to export traces to AWS X-Ray. It panics if the context has not been initialized with Context.
Types ¶
type TraceOption ¶
TraceOption is a function that configures a provider.
func WithDisabled ¶
func WithDisabled() TraceOption
WithDisabled disables tracing, not for use in production.
func WithExporter ¶ added in v0.5.0
func WithExporter(exporter sdktrace.SpanExporter) TraceOption
WithExporter sets the exporter to use.
func WithGRPCExporter ¶ added in v0.5.0
func WithGRPCExporter(conn *grpc.ClientConn) TraceOption
func WithMaxSamplingRate ¶
func WithMaxSamplingRate(rate int) TraceOption
WithMaxSamplingRate sets the maximum sampling rate in requests per second.
func WithSampleSize ¶
func WithSampleSize(size int) TraceOption
WithSampleSize sets the number of requests between two adjustments of the sampling rate.