Documentation
¶
Index ¶
- Constants
- Variables
- func EventConsumer() consumer.Middleware
- func EventsAddOpenTelemetry(eventName string) events.Middleware
- func HTTPInject(ctx context.Context, r *http.Request)
- func HTTPMiddleware(serviceName, handlerName, path string) func(http.Handler) http.Handler
- func InstrumentTransport(t http.RoundTripper) http.RoundTripper
- func NewHTTPHandler(handler http.Handler, operation string) http.Handler
- func SetUpOTel(serviceName string, log logger.Logger, opts ...Option) error
- func SpanAddErr(span trace.Span, err error)
- type Config
- type Option
Constants ¶
const ( AttrKeyEventName = attribute.Key("event.name") AttrKeyTrackingID = attribute.Key("tracking.id") )
OpenTelemetry attribute keys.
Variables ¶
var ( ErrEmptyServiceName = errors.New("serviceName cannot be empty") ErrTraceExporterNotFound = errors.New("OTEL Trace Exporter not found") )
Functions ¶
func EventConsumer ¶ added in v0.2.0
func EventConsumer() consumer.Middleware
func EventsAddOpenTelemetry ¶
func EventsAddOpenTelemetry(eventName string) events.Middleware
EventsAddOpenTelemetry adds an opentracing span to the context and finishes the span when the handler returns. Use go.opentelemetry.io/otel/trace.SpanFromContext to get the span from the context.
func HTTPInject ¶
HTTPInject injects OTel "cross-cutting concerns" (a.k.a OTel headers) and X-Tracking-Id into the outgoing request headers.
func HTTPMiddleware ¶
HTTPMiddleware returns a http.NewHandler and adds HTTP information on the span (similar to the otelhttp.NewHandler middleware) and adds extra information on top. Use go.opentelemetry.io/otel/trace.SpanFromContext to get the span from the context.
func InstrumentTransport ¶
func InstrumentTransport(t http.RoundTripper) http.RoundTripper
InstrumentTransport instruments the given http.RoundTripper with OTel. If the given http.RoundTripper is nil, http.DefaultTransport is used. Requests should be made with the context with the span.
func NewHTTPHandler ¶ added in v0.2.0
NewHTTPHandler wraps the passed handler in a span named like operation.
func SetUpOTel ¶
SetUpOTel perform all necessary initialisations for open telemetry and registers a trace provider. Any call to OTel API before the setup is done, will likely use the default noop implementations.
some values will be infered from env vars:
- OTEL_ENABLED: to activate/deactivate otel, default: true
- OTEL_DEBUG: to activate debug mode, default: false
- OTEL_TRACE_EXPORTER_OTLP_HTTP_ENDPOINT: otlp HTTP trace exporter is activated
- OTEL_TRACE_EXPORTER_OTLP_GRPC_ENDPOINT: otlp GRPC trace exporter is activated
- ENV: is the application environment
func SpanAddErr ¶
SpanAddErr adds an error, including stacktrace, to span and sets its status to error.
Types ¶
type Config ¶
type Config struct { Enable bool `json:"enable"` Debug bool `json:"debug"` Env string `json:"env"` ServiceName string `json:"serviceName"` ServiceVersion string `json:"serviceVersion"` // contains filtered or unexported fields }
Config holds the OTel configuration and is edited by Option.
type Option ¶
type Option func(config *Config)
Option applies a configuration to config.
func WithDebug ¶
func WithDebug() Option
WithDebug enables debug by adding a span processor which prints to stdout.
func WithEnvironment ¶
WithEnvironment adds env as the environment span attribute.
func WithErrorHandler ¶
WithErrorHandler registers h as OTel's global error handler. See go.opentelemetry.io/otel.ErrorHandler for more details on the error handler.
func WithGrpcTraceExporter ¶
WithGrpcTraceExporter registers an otlp trace exporter.
func WithHttpTraceExporter ¶
WithHttpTraceExporter registers an otlp http trace exporter.
func WithServiceVersion ¶
WithServiceVersion adds version as the service version span attribute.