Skip to content

Commit

Permalink
Use dynamic headers for otel-dc-llm (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
jinsongo authored Nov 2, 2024
1 parent 3caf966 commit 2568a1a
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
package com.instana.dc.llm.impl.llm;

import static com.instana.dc.DcUtil.OTEL_EXPORTER_OTLP_HEADERS;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.logging.Logger;

import com.google.common.collect.ImmutableList;
import com.instana.dc.HeadersSupplier;
import com.linecorp.armeria.common.HttpRequest;
import com.linecorp.armeria.common.RequestContext;
import com.linecorp.armeria.common.RequestHeaders;

import io.grpc.stub.StreamObserver;
import io.opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceRequest;
Expand Down Expand Up @@ -190,6 +197,26 @@ public void export(
ExportMetricsServiceRequest request,
StreamObserver<ExportMetricsServiceResponse> responseObserver) {

if (System.getenv(OTEL_EXPORTER_OTLP_HEADERS) == null) {
HttpRequest httpRequest = RequestContext.current().request();
RequestHeaders headers = httpRequest!=null ? httpRequest.headers() : null;
if ( headers != null ) {
HeadersSupplier supplier = HeadersSupplier.INSTANCE;
Map<String, String> newHeaders = new HashMap<>();
String xInstanaKey = headers.get("x-instana-key");
if (xInstanaKey != null && !xInstanaKey.isEmpty()) {
newHeaders.put("x-instana-key", xInstanaKey);
}
String xInstanaHost = headers.get("x-instana-host");
if (xInstanaHost != null && !xInstanaHost.isEmpty()) {
newHeaders.put("x-instana-host", xInstanaHost);
}
if ( ! newHeaders.isEmpty() ) {
supplier.updateHeaders(newHeaders);
}
}
}

synchronized (mutex) {
List<ResourceMetrics> allResourceMetrics = request.getResourceMetricsList();
for (ResourceMetrics resourceMetrics : allResourceMetrics) {
Expand Down

0 comments on commit 2568a1a

Please sign in to comment.