SDKs
JS/TS SDK
TypeScript SDK - Overview
10 min
the modular abv typescript sdk is built on opentelemetry for robust observability, better context management, and easy integration with third party libraries official link https //www npmjs com/package/@abvdev/core https //www npmjs com/package/@abvdev/core quickstart get your first trace into abv in just a few minutes 1\) install packages install the relevant packages to get started with tracing npm install @abvdev/tracing @abvdev/otel @opentelemetry/sdk node learn more about the packages typescript sdk overview /#packages 2\) set up environment variables add your abv credentials to your environment variables make sure that you have a env file in your project root and a package like dotenv to load the variables env abv api key = "sk abv " abv base url = "https //app abv dev" # us region \# abv base url = "https //eu app abv dev" # eu region 3\) set up opentelemetry create a file named instrumentation ts to initialize the opentelemetry sdk the abvspanprocessor is the key component that sends traces to abv instrumentation ts import { nodesdk } from "@opentelemetry/sdk node"; import { abvspanprocessor } from "@abvdev/otel"; const sdk = new nodesdk({ spanprocessors \[new abvspanprocessor()], }); sdk start(); modify instrumentation ts file to use dotenv package to load the variables additional parameters are provided to get trace visible in the ui immediately instrumentation ts import dotenv from "dotenv"; dotenv config(); import { nodesdk } from "@opentelemetry/sdk node"; import { abvspanprocessor } from "@abvdev/otel"; const sdk = new nodesdk({ spanprocessors \[ new abvspanprocessor({ apikey process env abv api key, baseurl process env abv base url, exportmode "immediate", flushat 1, flushinterval 1, additionalheaders { "content type" "application/json", "accept" "application/json" } }) ], }); sdk start(); import the instrumentation ts file at the very top of your application's entry point (e g , index ts ) index ts import " /instrumentation"; // must be the first import learn more about setting up opentelemetry typescript sdk setup docid\ ize1 ee38y2m1vyf9d 84 4\) instrument your application use one of the native abv framework integrations to automatically trace your application alternatively, manually instrument your application, e g by using the startactiveobservation this function takes a callback and automatically manages the observation's lifecycle and the opentelemetry context any observation created inside the callback will automatically be nested under the active observation, and the observation will be ended when the callback finishes this is just an example, check out the typescript sdk instrumentation docid\ mncioxz2ar176rewhcuzp page for more details index ts import " /instrumentation"; import { startactiveobservation } from "@abvdev/tracing"; async function main() { await startactiveobservation("my first trace", async (span) => { span update({ input "hello, abv!", output "this is my first trace!", }); }); } main(); 5\) run your application execute your application you should see your trace appear in the abv ui npx tsx index ts packages the abv sdk is designed to be modular here's an overview of the available packages package description environment @abvdev/core core utilities, types, and logger shared across packages universal js @abvdev/client client for features like prompts, datasets, and scores universal js @abvdev/tracing core opentelemetry based tracing functions ( startobservation , etc ) universal js @abvdev/otel the abvspanprocessor to export traces to abv node js ≥ 20 opentelemetry foundation building on opentelemetry is a core design choice for this sdk it offers several key advantages standardization it aligns with the industry standard for observability, making it easier to integrate with existing monitoring and apm tools robust context management opentelemetry provides reliable context propagation https //opentelemetry io/docs/concepts/context propagation/ , ensuring that traces are correctly linked even in complex, asynchronous applications ecosystem & interoperability you can leverage a vast ecosystem of third party instrumentations if a library you use supports opentelemetry, its traces can be sent to abv automatically learn more typescript sdk setup docid\ ize1 ee38y2m1vyf9d 84 typescript sdk instrumentation docid\ mncioxz2ar176rewhcuzp typescript sdk advanced configuration docid\ luroohdawr0r3fi8oet5j typescript sdk troubleshooting and faq docid\ gawyke2ibzt5ajlloqzka