Skip to content

OpenTelemetry ingestion

Ingest trace spans into Langfuse using the current OpenTelemetry endpoint.

This example assumes using Langfuse; is in scope and apiKey contains your Langfuse API key.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
using var client = new LangfuseClient(apiKey);

// Create a span and send it via OTLP/HTTP JSON ingestion.
var nowNanoseconds = (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() * 1_000_000).ToString();
var response = await client.Opentelemetry.OpentelemetryExportTracesAsync(
    resourceSpans:
    [
        new OtelResourceSpan
        {
            ScopeSpans =
            [
                new OtelScopeSpan
                {
                    Spans =
                    [
                        new OtelSpan
                        {
                            TraceId = Guid.NewGuid().ToString("N"),
                            SpanId = Guid.NewGuid().ToString("N")[..16],
                            Name = "sdk-integration-test",
                            Kind = 1,
                            StartTimeUnixNano = nowNanoseconds,
                            EndTimeUnixNano = nowNanoseconds,
                        },
                    ],
                },
            ],
        },
    ]);