Telemetry
Overview
BOSA Core provides a unified telemetry solution that use OpenTelemetry for observability and Sentry for error tracking. This integration enables you to monitor, debug, and optimize your applications. This integration helps you observe, debug, and optimize your applications with minimal configuration.
Integration Guide
This guide will help you integrate BOSA SDK Telemetry into your application in step by step. We'll start by configuring what telemetry options you'd like to enable and proceed to initializing it in your app.
Choose Your Telemetry Setup
Firstly, decide how you want to monitor your app:
Initialize Telemetry
Once you've choose and complete the configuration needed, initialize telemetry:
How to Use
For complete installation instructions and setup details, please refer to our Example. Currently BOSA Core Telemetry supports this following implementation patterns:
Sentry Integration
Sentry is an error monitoring and performance tracking service that helps identify and fix issues in applications. In BOSA Core, Sentry can be used in two ways:
Standalone: Captures uncaught exceptions and performance metrics
With OpenTelemetry: Sentry will acts as an OTLP trace receiver for distributed tracing
Under the hood, BOSA is using sentry SDK, you can use the same functionality from those SDK. for the documentation you can visit here
For this integration we can use sentry cloud service or using our GDP Labs sentry service in here (you need to contract our DSO team for access it)
OpenTelemetry Integration
OpenTelemetry, also known as OTel is an open-source observability framework that provides a standardized way to collect, process, and export telemetry data (traces, metrics, and logs) from your applications. BOSA Core telemetry uses OpenTelemetry's auto-instrumentation for FastAPI and LangChain operations.
The telemetry data can be exported in two ways:
Through an external OpenTelemetry backend (like Jaeger, Zipkin, or any OTLP-compatible system) by configuring the endpoint and port
Through Sentry integration, where traces are automatically forwarded to Sentry's performance monitoring system, providing additional error context and performance insights
This is the example if you want to add more instrumentation in your code, for example how to add instrumentation with HTTPX
install the dependencies open telemetry instrumentation https
Initiliaze the instrumentation
This is the list of instrumentation supported by open telemetry SDK: open telemetry instrumentation list
Custom Functions instrumentation
BOSA also provide custom functions instrumentation. this instrumentation can provide your functions to be instrumented. we currently support:
Class functions (CustomClass.function)
Module functions (module.function)
Static methods (@staticmethod)
Class methods (@classmethod)
This is the example of how to use Custom functions instrumentation,
you have a functions.py with path module that you want to instrument. this is the code:
and then you have this custom_class.py with path module.classes.custom_class that you want to instrument, this is the code:
This is the example how you can instrument that class & function:
From that example, the methods params in function instrument will be instrumented, the additional data that will be instrumented is only for input or output from that functions.
this is the example of additional data:
But, we have limitation for using this, the limitation is if you want to instrument a function you need to include the module for that function call. For example you can see in the example above, we have 2 function in functions.py file, sync_function and asyns_function . If we want to intrumented that function you need to call the function in your current implementation to become like this
Trace Sampler
BOSA Telemetry supports custom trace samplers for OpenTelemetry, allowing you to define your own sampling logic. To create one, you must implement the Sampler abstract class provided by the OpenTelemetry SDK. Below is the example of custom Sampler:
To use the custom sampler, provide an instance of it to OpenTelemetryConfig
API Reference
TelemetryConfig
TelemetryConfig is a wrapper configuration object that holds your telemetry setup. Pass this to init_telemetry().
Parameters:
sentry_config: SentryConfig | None = None— optional. Enables Sentry error tracking and performance monitoring.otel_config: OpenTelemetryConfig | None = None— optional. Enables OpenTelemetry tracing to external exporters or Sentry.
Use either, both, or none (no-op).
OpenTelemetryConfig
Parameters:
endpoint: str— the hostname (include port) of your OTLP-compatible trace exporter (e.g., Jaeger, Tempo).trace_sampler: Sampler— the OpenTelemetry Sampler to sampling traces.headers: dict[str, str]— the header sent to connect to OpenTelemetry exporter.attributes: dict[str, str]— a dictionary of resource-level tags (e.g.,"service.name": "bosa-api").use_grpc: bool— if True, wil connect using GRPC to exporter, otherwise will use HTTP.fastapi_config: FastAPIConfig | None— optional. Enables automatic FastAPI instrumentation.use_langchain: bool = True— if enabled, automatically instruments LangChain-based pipelines.use_httpx: bool = True— if enabled, automatically instruments HTTPX library.use_requests: bool = True— if enabled, automatically instruments python Requests library.
SentryConfig
Parameters:
dsn: str— your Sentry project DSN.environment: str— deployment environment (e.g., "production").release: str— application version tag.profiles_sample_rate: float | None— optional, Sentry performance sample rate.send_default_pii: bool | None— whether to send PII (e.g., usernames, emails) to Sentry.traces_sampler— a callable to control dynamic sampling.open_telemetry_config: OpenTelemetryConfig | None— if provided, links Sentry to OpenTelemetry spans.**kwargs— other parameters supported bysentry_sdk.init().
init_telemetry(config: TelemetryConfig)
Initializes the appropriate telemetry layers according to the provided config.
If
sentry_configis present, initializes Sentry (either use sentry only or with telemetry).If
otel_configis present, sets the global tracer (Only supply it while using external exporter).
Last updated