Python Tracer SDK

Install

poetry add autoblocksai

AutoblocksTracer

The AutoblocksTracer class is used to send events to Autoblocks. It can be initialized without any arguments if your ingestion key is set as an environment variable named AUTOBLOCKS_INGESTION_KEY.

Python

from autoblocks.tracer import AutoblocksTracer

tracer = AutoblocksTracer()

Otherwise, you can pass the ingestion key as an argument:

Python

tracer = AutoblocksTracer("your-ingestion-key")

There are additional arguments that you can use to further configure the tracer:

  • Name
    trace_id
    Type
    Optional[str]
    Description

    The trace_id for all events sent through the tracer instance.

  • Name
    properties
    Type
    Optional[dict]
    Description

    The properties that will be sent for all events sent through the tracer instance.

  • Name
    timeout
    Type
    timedelta | undefined
    Description

    The timeout for each send_event call, which is a POST request to the Autoblocks ingestion API. Default value is timedelta(seconds=5).

Python

from datetime import timedelta

tracer = AutoblocksTracer(
  trace_id="my-trace-id",
  properties={"source": "my-app"},
  timeout=timedelta(seconds=1),
)

send_event

Send an event to Autoblocks.

Python

tracer.send_event(
  "ai.request",
  properties={
    "provider": "openai",
    "prompt": "Hello!",
  },
)

Arguments

  • Name
    message
    Type
    str
    Description

    The name of the event.

  • Name
    trace_id
    Type
    Optional[str]
    Description

    Used to group related events together. If not provided, defaults to a random UUID.

  • Name
    properties
    Type
    Optional[dict]
    Description

    Custom properties to attach to the event. The values in this dictionary can be anything, including other dictionaries.

  • Name
    span_id
    Type
    Optional[str]
    Description

    Within a trace, connect related events together using span IDs. This is useful to connect request and response events together, for example.

  • Name
    parent_span_id
    Type
    Optional[str]
    Description

    Establish parent / child relationships between your spans using parent span IDs. For example, if some events represent work being done on behalf of a higher level span in your trace, you should set that span's ID as the parent span ID for those events.

  • Name
    timestamp
    Type
    Optional[str]
    Description

    An ISO date time string of when the event happened. If not provided, defaults to the current time.

Returns

set_trace_id

Use this method to set the trace_id for all subsequent calls of send_event.

Python

tracer.set_trace_id('my-trace-id')

Arguments

  • Name
    trace_id
    Type
    str
    Description

    The trace_id to set.

set_properties

Use this method to set the properties for all subsequent calls of send_event.

Python

tracer.set_properties({"x": 1, "y": 2})  # --> {"x": 1, "y": 2}
tracer.set_properties({"x": 2})  # --> {"x": 2}

Arguments

  • Name
    properties
    Type
    dict
    Description

    The properties to set.

update_properties

Use this method to update the properties for all subsequent calls of send_event.

Python

tracer.update_properties({"x": 1, "y": 2})  # --> {"x": 1, "y": 2}
tracer.update_properties({"x": 2})  # --> {"x": 2, "y": 2}

Arguments

  • Name
    properties
    Type
    dict
    Description

    The properties to update.

AutoblocksAPIClient