barrel_trace (barrel_docdb v1.1.1)

View Source

Distributed 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_context(Ctx) deprecated

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

add_event(Name)

-spec add_event(binary()) -> ok.

Add an event to the current span.

add_event(Name, Attrs)

-spec add_event(binary(), map()) -> ok.

Add an event with attributes to the current span.

attach_context(Ctx)

This function is deprecated. Use with_extracted_context/2 for proper context cleanup..
-spec attach_context(map()) -> ok.

Attach an extracted context to the current process.

db_attributes(Db)

-spec db_attributes(binary() | undefined) -> map().

Generate database attributes for a span.

db_attributes(Db, Op)

-spec db_attributes(binary() | undefined, atom() | undefined) -> map().

Generate database attributes with operation.

extract_headers(Headers)

This function is deprecated. Use with_extracted_context/2 for proper context cleanup..
-spec extract_headers(list()) -> ok.

Extract trace context from HTTP headers. Returns the extracted context (attached to current process).

http_attributes(Method, Path)

-spec http_attributes(binary(), binary()) -> map().

Generate HTTP attributes for a span.

http_attributes(Method, Path, StatusCode)

-spec http_attributes(binary(), binary(), integer()) -> map().

Generate HTTP attributes with status code.

inject_headers(Headers)

-spec inject_headers(list()) -> list().

Inject trace context into HTTP headers. Returns a list of {HeaderName, HeaderValue} tuples to add to outgoing requests.

is_recording()

-spec is_recording() -> boolean().

Check if the current span is recording. Use this to guard expensive attribute computation.

record_error(Error)

-spec record_error(term()) -> ok.

Record an error on the current span.

record_error(Error, Attrs)

-spec record_error(term(), map()) -> ok.

Record an error with additional attributes.

set_attribute(Key, Value)

-spec set_attribute(term(), term()) -> ok.

Set a single attribute on the current span.

set_attributes(Attrs)

-spec set_attributes(map()) -> ok.

Set multiple attributes on the current span.

with_db_span(Op, Db, Fun)

-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).

with_db_span(Op, Db, ExtraAttrs, Fun)

-spec with_db_span(atom(), binary() | undefined, map(), fun(() -> Result)) -> Result
                      when Result :: term().

Execute a function within a database span with extra attributes.

with_extracted_context(Headers, Fun)

-spec with_extracted_context(list(), fun(() -> Result)) -> Result when Result :: term().

Execute function with trace context extracted from HTTP headers. This properly scopes the context and ensures cleanup via detach.

with_http_span(Method, Path, Fun)

-spec with_http_span(binary(), binary(), fun(() -> Result)) -> Result when Result :: term().

Execute a function within an HTTP server span. Creates a span for incoming HTTP requests.

with_http_span(Method, Path, ExtraAttrs, Fun)

-spec with_http_span(binary(), binary(), map(), fun(() -> Result)) -> Result when Result :: term().

Execute a function within an HTTP server span with extra attributes.