Go API Documentation

github.com/caddyserver/caddy/v2/modules/caddyhttp/tracing

No package summary is available.

Package

Files: 3. Third party imports: 10. Imports from organisation: 0. Tests: 0. Benchmarks: 0.

Constants

Vars

globalTracerProvider stores global tracer provider and is responsible for graceful shutdown when nobody is using it.

Types

Tracing

Tracing implements an HTTP handler that adds support for distributed tracing, using OpenTelemetry. This module is responsible for the injection and propagation of the trace context. Configure this module via environment variables (see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/sdk-environment-variables.md). Some values can be overwritten in the configuration file.

Field name Field type Comment
SpanName

string

SpanName is a span name. It should follow the naming guidelines here: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/api.md#span

otel

openTelemetryWrapper

otel implements opentelemetry related logic.

logger

*zap.Logger

No comment on field.

nextCall

nextCall store the next handler, and the error value return on calling it (if any)

Field name Field type Comment
next

caddyhttp.Handler

No comment on field.
err

error

No comment on field.

openTelemetryWrapper

openTelemetryWrapper is responsible for the tracing injection, extraction and propagation.

Field name Field type Comment
propagators

propagation.TextMapPropagator

No comment on field.
handler

http.Handler

No comment on field.
spanName

string

No comment on field.

tracerProvider

This type doesn't have documentation.

Field name Field type Comment
mu

sync.Mutex

No comment on field.
tracerProvider

*sdktrace.TracerProvider

No comment on field.
tracerProvidersCounter

int

No comment on field.

Functions

func (*Tracing) Cleanup

Cleanup implements caddy.CleanerUpper and closes any idle connections. It calls Shutdown method for a trace provider https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk.md#shutdown.

Uses: fmt.Errorf.

func (*Tracing) Provision

Provision implements caddy.Provisioner.

func (*Tracing) ServeHTTP

ServeHTTP implements caddyhttp.MiddlewareHandler.

func (*Tracing) UnmarshalCaddyfile

UnmarshalCaddyfile sets up the module from Caddyfile tokens. Syntax:

tracing {
    [span <span_name>]
}

Uses: caddyfile.Dispenser.

func (*openTelemetryWrapper) ServeHTTP

ServeHTTP propagates call to the by wrapped by otelhttp next handler.

Uses: context.WithValue.

func (Tracing) CaddyModule

CaddyModule returns the Caddy module information.

Private functions

func init

References: httpcaddyfile.RegisterHandlerDirective.

func newOpenTelemetryWrapper

newOpenTelemetryWrapper is responsible for the openTelemetryWrapper initialization using provided configuration.

References: autoprop.NewTextMapPropagator, fmt.Errorf, http.HandlerFunc, otelhttp.NewHandler, otelhttp.WithPropagators, otelhttp.WithSpanNameFormatter, otelhttp.WithTracerProvider, otlptracegrpc.New, sdktrace.WithBatcher, sdktrace.WithResource.

func parseCaddyfile

func cleanup

cleanup flush all remaining data and shutdown a tracerProvider

func newResource

newResource creates a resource that describe current handler instance and merge it with a default attributes value.

References: resource.Default, resource.Merge, resource.NewSchemaless, semconv.WebEngineName, semconv.WebEngineVersion.

func serveHTTP

serveHTTP injects a tracing context and call the next handler.

References: caddyhttp.ExtraLogFields, caddyhttp.ExtraLogFieldsCtxKey, caddyhttp.SetVar, propagation.HeaderCarrier, trace.SpanContextFromContext, zap.String.

func spanNameFormatter

spanNameFormatter performs the replacement of placeholders in the span name

func cleanupTracerProvider

cleanupTracerProvider gracefully shutdown a TracerProvider

References: context.Background, fmt.Errorf, zap.Error, zapcore.ErrorLevel.

func getTracerProvider

getTracerProvider create or return an existing global TracerProvider

References: sdktrace.NewTracerProvider.


Tests

Files: 3. Third party imports: 1. Imports from organisation: 0. Tests: 8. Benchmarks: 0.

Test functions

TestOpenTelemetryWrapper_newOpenTelemetryWrapper

References: context.Background.

TestTracing_ServeHTTP_Next_Error

References: caddyhttp.HandlerFunc, context.Background, errors.Is, errors.New, http.Request, http.ResponseWriter, httptest.NewRecorder.

TestTracing_ServeHTTP_Propagation_With_Initial_Headers

References: caddyhttp.HandlerFunc, context.Background, http.Request, http.ResponseWriter, httptest.NewRecorder, strings.HasPrefix.

TestTracing_ServeHTTP_Propagation_Without_Initial_Headers

References: caddyhttp.HandlerFunc, context.Background, http.Request, http.ResponseWriter, httptest.NewRecorder, strings.HasPrefix.

TestTracing_UnmarshalCaddyfile

References: caddyfile.Dispenser, caddyfile.NewTestDispenser, testing.T.

TestTracing_UnmarshalCaddyfile_Error

References: caddyfile.Dispenser, caddyfile.NewTestDispenser, testing.T.

Test_tracersProvider_cleanupTracerProvider

References: zap.NewNop.

Test_tracersProvider_getTracerProvider