Skip to content

Commit e8cc938

Browse files
Fix recording open telemetry LLM metrics (#1443)
Co-authored-by: Waldek Mastykarz <waldek@mastykarz.nl>
1 parent bdd3716 commit e8cc938

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

DevProxy.Plugins/Inspection/OpenAITelemetryPlugin.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,20 @@ private void InitializeOpenTelemetryExporter()
218218

219219
try
220220
{
221-
void configureOtlpExporter(OtlpExporterOptions options)
221+
var baseExporterUri = new Uri(Configuration.ExporterEndpoint);
222+
223+
void configureTracesOtlpExporter(OtlpExporterOptions options)
224+
{
225+
// We use protobuf to allow intercepting Dev Proxy's own LLM traffic
226+
options.Protocol = OtlpExportProtocol.HttpProtobuf;
227+
options.Endpoint = new Uri(baseExporterUri, "/v1/traces");
228+
}
229+
230+
void configureMetricsOtlpExporter(OtlpExporterOptions options)
222231
{
223232
// We use protobuf to allow intercepting Dev Proxy's own LLM traffic
224233
options.Protocol = OtlpExportProtocol.HttpProtobuf;
225-
options.Endpoint = new Uri(Configuration.ExporterEndpoint + "/v1/traces");
234+
options.Endpoint = new Uri(baseExporterUri, "/v1/metrics");
226235
}
227236

228237
var resourceBuilder = ResourceBuilder
@@ -232,7 +241,7 @@ void configureOtlpExporter(OtlpExporterOptions options)
232241
_tracerProvider = Sdk.CreateTracerProviderBuilder()
233242
.SetResourceBuilder(resourceBuilder)
234243
.AddSource(ActivitySourceName)
235-
.AddOtlpExporter(configureOtlpExporter)
244+
.AddOtlpExporter(configureTracesOtlpExporter)
236245
.Build();
237246

238247
_meterProvider = Sdk.CreateMeterProviderBuilder()
@@ -247,7 +256,7 @@ void configureOtlpExporter(OtlpExporterOptions options)
247256
Boundaries = [0.0001, 0.0005, 0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1, 5, 10, 50, 100]
248257
})
249258
.AddView(SemanticConvention.GEN_AI_USAGE_TOTAL_COST, new MetricStreamConfiguration())
250-
.AddOtlpExporter(configureOtlpExporter)
259+
.AddOtlpExporter(configureMetricsOtlpExporter)
251260
.Build();
252261

253262
_tokenUsageMetric = _meter.CreateHistogram<long>(

0 commit comments

Comments
 (0)