SDK Functions
Distributional is now Talaria Scientific. The DBNL product described in these docs has been sunset; this documentation is preserved for reference. Read the announcement.
convert_otlp_traces_data
dbnl.convert_otlp_traces_data(data: pd.Series[Any],
format: Literal['otlp_json',
'otlp_proto'] | None = None
) → pd.Series[Any]Converts a Series of OTLP TracesData to a Series of DBNL spans matching the DBNL semantic convention.
The resulting Series can be used as is to fill the spans column of a DataFrame to be logged with the dbnl.log function.
For a complete specification of the TracesData format, see the OTLP specification
Parameters:
data: Series of OTLP TracesDataformat: OTLP TracesData format (otlp_jsonorotlp_proto) orNoneto infer from data
Returns: Series of spans data
create_filter
dbnl.create_filter(project_id: str,
name: str,
table: Literal['spans',
'traces',
'sessions'],
description: str | None = None,
conditions: list[FilterCondition] | None = None,
expression: str | None = None
) → FilterCreate a new Filter
Parameters:
project_id: The Project ID to create the Filter forname: Name for the Filtertable: Table to create the Filter fordescription: Optional description of the Filterconditions: Conditions for the Filterexpression: Expression string e.g. length(traces.input) > 10
Returns: Created Filter
create_llm_model
Create an LLM Model.
Parameters:
name: Model namedescription: Model description, defaults toNonetype: Model type (e.g. completion or embedding), defaults to “completion”provider: Model provider (e.g. openai, bedrock, etc.)model: Model (e.g. gpt-4, gpt-3.5-turbo, etc.)params: Model provider parameters (e.g. api key), defaults toNone
Returns: LLM Model
create_metric
Create a new Metric
Parameters:
name: Name for the Metrictable: Table to create the Metric forexpression: Expression string e.g. length(traces.input)description: Optional description of what computation the metric is performinggreater_is_better: Flag indicating whether greater values are semantically ‘better’ than lesser values
Raises:
DBNLNotLoggedInError: dbnl SDK is not logged in. Seelogin.DBNLInputValidationError: Input does not conform to expected format
Returns: Created Metric
create_project
Create a new Project
Parameters:
name: Name for the Projectdescription: Description for the Project, defaults toNone. Description is limited to 255 characters.default_llm_model_id: Default model connection used for LLM metrics that don’t specify a model. IfNone,the global default model connection will be used, if configured.default_llm_model_name: Default model connection (by name) used for LLM metrics that don’t specify a model. IfNone,the global default model connection will be used, if configured. Only one ofdefault_llm_model_idanddefault_llm_model_namecan be provided.
Returns: Project
Examples:
delete_filter
Delete a Filter by id
Parameters:
filter_id: Filter id
Returns:
None
delete_llm_model
Delete an LLM Model by id.
delete_metric
Delete a Metric by ID
Parameters:
metric_id: ID of the metric to delete
Raises:
DBNLNotLoggedInError: dbnl SDK is not logged in. Seelogin.DBNLAPIValidationError: dbnl API failed to validate the request
Returns:
None
flatten_otlp_traces_data
Flattens a Series of OTLP TracesData to a DataFrame matching the DBNL semantic convention.
The resulting DataFrame can be used as is to be logged with the dbnl.log function and will included all minimally required columns (timestamp, input, output) as well as the spans column for further flattening server-side.
For a complete specification of the TracesData format, see the OTLP specification
Parameters:
data: Series of OTLP TracesDataformat: OTLP TracesData format (otlp_jsonorotlp_proto) orNoneto infer from data
Returns: DataFrame with columns timestamp, input, output, spans
get_dbnl_exporter
Return an OTLP span exporter configured for the dbnl ingestion endpoint.
Useful when you manage your own TracerProvider and want to wire dbnl into an existing pipeline without init_tracing().
Requires dbnl.login() to have been called first.
Parameters:
project_id: dbnl project ID used to route ingested traces.namespace_id: dbnl namespace ID used to route ingested traces. When omitted, the header is not sent and the server uses the organization’s default namespace.
Returns: A configured
OTLPSpanExporter.
get_dbnl_span_processor
Return a BatchSpanProcessor wrapping the dbnl OTLP exporter.
A single call to provider.add_span_processor(get_dbnl_span_processor(...)) is all that’s needed to send traces to dbnl from any TracerProvider.
Requires dbnl.login() to have been called first.
Parameters:
project_id: dbnl project ID used to route ingested traces.namespace_id: dbnl namespace ID used to route ingested traces. When omitted, the header is not sent and the server uses the organization’s default namespace.
Returns: A
BatchSpanProcessorready to be added to a provider.
get_filter
Get a Filter by id or name.
Parameters:
filter_id: Filter idname: Filter name
Returns: Filter
Examples:
get_llm_model
Get an LLM Model by id or name.
Examples:
get_metric
Get a Metric by ID or name.
Parameters:
metric_id: ID of the metric to getname: Name of the metric to get
Raises:
DBNLNotLoggedInError: dbnl SDK is not logged in. Seelogin.DBNLAPIValidationError: dbnl API failed to validate the request
Returns: The requested metric
Examples:
get_or_create_filter
Get a Filter by name, or create it if it does not exist.
Parameters:
project_id: The Project ID to get the Filter forname: Name of the Filter to gettable: Table to get the Filter fordescription: Optional description of the Filterconditions: Conditions for the Filterexpression: Expression string e.g. length(traces.input) > 10
Returns: Filter
get_or_create_llm_model
Get an LLM Model by name, or create it if it does not exist.
Parameters:
name: Model namedescription: Model description, defaults toNonetype: Model type (e.g. completion or embedding), defaults to “completion”provider: Model provider (e.g. openai, bedrock, etc.)model: Model (e.g. gpt-4, gpt-3.5-turbo, etc.)params: Model provider parameters (e.g. api key), defaults toNone
Returns: Model
get_or_create_metric
Get a Metric by name, or create it if it does not exist.
Parameters:
name: Name of the Metric to gettable: Table to get the Metric forexpression: Expression string e.g. length(traces.input)description: Optional description of what computation the metric is performinggreater_is_better: Flag indicating whether greater values are semantically ‘better’ than lesser values
Examples:
get_or_create_project
Get the Project with the specified name or create a new one if it does not exist
Parameters:
name: Name for the Projectdescription: Description for the Project, defaults toNonedefault_llm_model_id: Default model connection used for LLM metrics that don’t specify a model. IfNone,the global default model connection will be used, if configured.default_llm_model_name: Default model connection (by name) used for LLM metrics that don’t specify a model. IfNone,the global default model connection will be used, if configured. Only one ofdefault_llm_model_idanddefault_llm_model_namecan be provided.
Raises:
DBNLNotLoggedInError: dbnl SDK is not logged in. Seelogin.DBNLAPIValidationError: dbnl API failed to validate the request
Returns: Newly created or matching existing Project
Examples:
get_project
Retrieve a Project by id or name.
Parameters:
project_id: The id for the existing Project.name: The name for the existing Project.
Returns: Project
Examples:
init_tracing
Initialize OpenTelemetry tracing for the dbnl platform.
Configures a TracerProvider with an OTLP HTTP exporter that sends traces to the dbnl ingestion endpoint. The provider is registered as the global tracer provider so any opentelemetry instrumentation picks it up automatically.
When tracer_provider is supplied, the dbnl span processor is added to it directly. The provider is not registered as the global tracer provider and is not tracked internally; the caller owns the lifecycle.
Requires dbnl.login() to have been called first.
Parameters:
project_id: dbnl project ID used to route ingested traces.namespace_id: dbnl namespace ID used to route ingested traces. When omitted, the header is not sent and the server uses the organization’s default namespace.service_name: Convenience shorthand that creates aResourcewithservice.nameset to this value. Ignored when resource or*tracer_provider*is provided.resource: An OpenTelemetryResourceattached to the provider. Takes precedence over*service_name*. Ignored when*tracer_provider*is provided.tracer_provider: An existingTracerProviderto attach the dbnl span processor to. When provided,*service_name*and resource are ignored, the provider is not set as the global tracer provider, and no duplicate-call warning is issued.auto_instrument: WhenTrue(default), automatically discovers and instruments all installed OpenInference instrumentor packages.
Returns: The configured
TracerProvider.
log
Log OTLP trace data for a date range to a project.
Parameters:
project_id: The Project id to send the logs to.otlp_data: Pandas Series of OTLP TracesData (proto bytes or JSON).data_start_time: Data start date.data_end_time: Data end time.otlp_format: OTLP format (“otlp_json”or“otlp_proto”),orNoneto auto-detect.wait_timeout: If set, the function will block for up towait_timeoutseconds until the data is done processing, defaults to 10 minutes.
Raises:
DBNLNotLoggedInError: dbnl SDK is not logged in. Seelogin.DBNLInputValidationError: Input does not conform to expected format
login
Setup dbnl SDK to make authenticated requests. After login is run successfully, the dbnl client will be able to issue secure and authenticated requests against hosted endpoints of the dbnl service.
Parameters:
api_token: dbnl API token for authentication; token can be found at/tokenspage of the dbnl app. IfNoneis provided, the environment variableDBNL_API_TOKENwill be used by default.namespace_id: The namespace ID to use for the session.api_url: The base url of the Distributional API. By default, this is set tolocalhost:8080/api,for sandbox users. For other users, please contact your sys admin. IfNoneis provided, the environment variableDBNL_API_URLwill be used by default.app_url: An optional base url of the Distributional app. If this variable is not set, the app url is inferred from theDBNL_API_URLvariable. For on-prem users, please contact your sys admin if you cannot reach the Distributional UI.
update_filter
Update a Filter by id
Parameters:
filter_id: Filter idname: Filter namedescription: Filter descriptionconditions: Filter conditionsexpression: Filter expression
Returns: Updated Filter
update_llm_model
Update an LLM Model by id.
Parameters:
llm_model_id: Model idname: Model namedescription: Model description, defaults toNonemodel: Model (e.g. gpt-4, gpt-3.5-turbo, etc.)params: Model provider parameters (e.g. api key), defaults to{}
Returns: Updated LLM Model