barrel_trace (barrel_docdb v1.1.1)
View SourceDistributed tracing helpers for barrel_docdb
Provides OpenTelemetry-compatible tracing with semantic conventions for database operations following the OpenTelemetry Database Spans specification.
Semantic conventions: - db.system.name: "barrel" - db.namespace: database name - db.collection.name: collection/table name - db.operation.name: operation type (get, put, delete, query) - db.query.text: query text (sanitized) - db.response.returned_rows: number of rows returned
Summary
Functions
Add an event to the current span.
Add an event with attributes to the current span.
Attach an extracted context to the current process.
Generate database attributes for a span.
Generate database attributes with operation.
Extract trace context from HTTP headers. Returns the extracted context (attached to current process).
Generate HTTP attributes for a span.
Generate HTTP attributes with status code.
Inject trace context into HTTP headers. Returns a list of {HeaderName, HeaderValue} tuples to add to outgoing requests.
Check if the current span is recording. Use this to guard expensive attribute computation.
Record an error on the current span.
Record an error with additional attributes.
Set a single attribute on the current span.
Set multiple attributes on the current span.
Execute a function within a database span. Creates a span with OpenTelemetry database semantic conventions.
Execute a function within a database span with extra attributes.
Execute function with trace context extracted from HTTP headers. This properly scopes the context and ensures cleanup via detach.
Execute a function within an HTTP server span. Creates a span for incoming HTTP requests.
Execute a function within an HTTP server span with extra attributes.
Functions
-spec add_event(binary()) -> ok.
Add an event to the current span.
Add an event with attributes to the current span.
-spec attach_context(map()) -> ok.
Attach an extracted context to the current process.
Generate database attributes for a span.
Generate database attributes with operation.
-spec extract_headers(list()) -> ok.
Extract trace context from HTTP headers. Returns the extracted context (attached to current process).
Generate HTTP attributes for a span.
Generate HTTP attributes with status code.
Inject trace context into HTTP headers. Returns a list of {HeaderName, HeaderValue} tuples to add to outgoing requests.
-spec is_recording() -> boolean().
Check if the current span is recording. Use this to guard expensive attribute computation.
-spec record_error(term()) -> ok.
Record an error on the current span.
Record an error with additional attributes.
Set a single attribute on the current span.
-spec set_attributes(map()) -> ok.
Set multiple attributes on the current span.
-spec with_db_span(atom(), binary() | undefined, fun(() -> Result)) -> Result when Result :: term().
Execute a function within a database span. Creates a span with OpenTelemetry database semantic conventions.
Example:
barrel_trace:with_db_span(put, Db, fun() ->
do_put(Db, DocId, Doc)
end).
-spec with_db_span(atom(), binary() | undefined, map(), fun(() -> Result)) -> Result when Result :: term().
Execute a function within a database span with extra attributes.
Execute function with trace context extracted from HTTP headers. This properly scopes the context and ensures cleanup via detach.
Execute a function within an HTTP server span. Creates a span for incoming HTTP requests.
Execute a function within an HTTP server span with extra attributes.