While Langtrace Cloud is the default destination for your traces, there are scenarios where you might need to send traces to a custom endpoint. This could be for testing, using an on-premises solution, or integrating with other systems. This guide covers two methods to achieve this: using the api_host parameter or implementing a custom exporter.
The api_host option allows you to specify a custom endpoint to send traces to. This is particularly useful when you want to send traces to a different endpoint than the default Langtrace Cloud.
If no custom endpoint is specified, traces will be sent to Langtrace Cloud by default.The precedence order for determining the API host is as follows:
The environment variable LANGTRACE_API_HOST
The environment variable OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
The environment variable OTEL_EXPORTER_OTLP_ENDPOINT
The api_host parameter in the Langtrace.init function
Allows you to specify whether to batch spans before sending. This is useful for reducing the number of requests sent to the server, which can improve performance and reduce costs.
If you are using the SDK in a script or a notebook, you might want to set this
to false to see the spans as they are captured.
Copy
from langtrace_python_sdk import langtracelangtrace.init( batch=False)
Allows you to specify whether to write spans to the console output.
This is useful if you have a logforwarded that forwards console output or for debugging.
If this is set to true, the spans will not be sent to the remote endpoint.
Copy
from langtrace_python_sdk import langtracelangtrace.init( write_spans_to_console=True)
By defining a custom exporter, you have full control over the export process, including custom formatting or additional processing of spans before sending.If you want to send traces to a remote endpoint, instead of defining api_host, it can be done by passing a custom exporter to the custom_remote_exporter parameter in the Langtrace.init function.
The custom_remote_exporter option will take precedence over the api_host option.
Using the custom_remote_exporter with a custom url will cause majority of
the langtrace features (like evaluations, user feedback, etc.) to not work and
should only be used if Langtrace is being used only to capture and
send traces.
Here is an example of how to implement a custom exporter that demonstrates that with a custom exporter you have endless possibilities!
Typescript SDK
Python SDK
Copy
import * as Langtrace from "@langtrase/typescript-sdk";import { CustomExporter } from './custom_exporter'Langtrace.init({ write_spans_to_console: true, custom_remote_exporter: new CustomExporter("https://example.com/")})// Your application code here
With this option, certain libraries can be either excluded or included from being traced.
This enables users to have more control over what is being traced and easily filter out noisy libraries.This option can be used to exclude a library from being traced by passing the library name to the disable_instrumentations parameter in the Langtrace.init function.
To include specific vendors, you can pass the value to this parameter as follows:
Copy
{ "only": ["weaviate", "gemini"] }
This way, only weaviate and gemini will be traced.For Python SDK, the vendor name can be found in the all_instrumentations variable in the repo here.For Typescript SDK, the vendor name can be found in the allInstrumentations variable in the repo here.
This option allows you to exclude specific functions from being traced. This can be useful if you have certain functions that you do not want to trace, such as health check functions.To exclude a function, do it the following way:
This option allows you to specify the name of the service for which traces are generated.
This is useful if you have multiple services within your application and want to trace them separately.
This option overrides the attribute service.name in the trace as per the OpenTelemetry specification.The precedence order for determining the service name is as follows:
The environment variable OTEL_SERVICE_NAME
The service_name parameter in the Langtrace.init function
Copy
from langtrace_python_sdk import langtracelangtrace.init( service_name="your_service_name")
This option allows you to disable logging within the SDK. This is useful if you have a logging system in place and do not want Langtrace to log anything.
Copy
from langtrace_python_sdk import langtracelangtrace.init( disable_logging=True)
This argument is only applicable for Typescript SDK with Next.js.
This option allows you to specify the instrumentations to be used. This is useful if you have a custom implementation of a library and want to trace it.
Copy
import * as Langtrace from "@langtrase/typescript-sdk";Langtrace.init({ instrumentations: { openai: openai, },});
This argument is only applicable for Typescript SDK.
Flag to disable the latest version check. This removes any version checks that happens on every init call.
Copy
import * as Langtrace from "@langtrase/typescript-sdk";Langtrace.init({ disable_latest_version_check: true,});