Skip to content

SDK Configuration

This page explains how to configure the OpenTelemetry SDK for Tracy.

Configuring the OpenTelemetry SDK

The configureOpenTelemetrySdk() function initializes the OpenTelemetry SDK with the provided exporter configuration.

Parameter Type Required Default Description
exporterConfig BaseExporterConfig Yes - The exporter configuration (Langfuse, Weave, Console, File, or OTLP HTTP)
additionalResource Resource No service.name = "unknown-service" Additional OpenTelemetry resource attributes

Setting Service Name

You can customize the service name, service version, and other resource attributes:

val sdk = configureOpenTelemetrySdk(
    exporterConfig = LangfuseExporterConfig(),
    additionalResource = Resource.create(
        Attributes.of(
            AttributeKey.stringKey("service.name"), "my-ai-application",
            AttributeKey.stringKey("service.version"), "1.0.0"
        )
    )
)

Common Exporter Settings

All exporter configurations accept an ExporterCommonSettings object that controls common behavior:

Property Type Default Environment Variable Description
traceToConsole Boolean false - Additionally log spans to console for debugging
flushIntervalMs Long 5 - Delay between batch export attempts (in milliseconds)
flushThreshold Int 512 - Maximum number of spans per export batch
flushOnShutdown Boolean true - Flush pending spans when JVM shuts down
maxNumberOfSpanAttributes Int? 256 MAX_NUMBER_OF_SPAN_ATTRIBUTES Maximum number of attributes per span
maxSpanAttributeValueLength Int? Int.MAX_VALUE MAX_SPAN_ATTRIBUTE_VALUE_LENGTH Maximum length for attribute values

Example with Custom Settings

val sdk = configureOpenTelemetrySdk(
    LangfuseExporterConfig(
        settings = ExporterCommonSettings(
            traceToConsole = true,           // Also log to console
            flushIntervalMs = 10,            // Flush every 10 milliseconds
            flushThreshold = 256,            // Batch size of 256 spans
            flushOnShutdown = true,          // Flush on JVM shutdown
            maxNumberOfSpanAttributes = 512, // Allow more attributes
        )
    )
)

Using an Existing OpenTelemetry SDK

If your project already has an OpenTelemetrySdk configured, you can pass it directly to Tracy via TracingManager.setSdk() without calling configureOpenTelemetrySdk():

val sdk: OpenTelemetrySdk = initializeOpenTelemetry() // your existing setup
TracingManager.setSdk(sdk)

Tracy respects the active OTel context, so any spans you create using your own tracer will automatically become parents of Tracy spans as long as the context is active when Tracy-instrumented code runs.

Note

When passing a custom SDK, you are responsible for its lifecycle — flushing, shutdown, and span processor configuration.

See the OpenTelemetry Integration Example for a complete, runnable demonstration.