diff --git a/host/build.gradle b/host/build.gradle index be96739..01dbffc 100644 --- a/host/build.gradle +++ b/host/build.gradle @@ -21,7 +21,7 @@ dependencies { implementation("io.opentelemetry.semconv:opentelemetry-semconv:1.23.1-alpha") implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.16.0-rc1") implementation("org.snmp4j:snmp4j-agent:3.8.1") - implementation(files("libs/otel-dc-0.9.9.jar")) + implementation(files("libs/otel-dc-0.10.0.jar")) implementation(files("libs/simp-snmp-0.1.3.jar")) testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.1") diff --git a/host/libs/otel-dc-0.10.0.jar b/host/libs/otel-dc-0.10.0.jar new file mode 100644 index 0000000..19c967c Binary files /dev/null and b/host/libs/otel-dc-0.10.0.jar differ diff --git a/host/libs/otel-dc-0.9.9.jar b/host/libs/otel-dc-0.9.9.jar deleted file mode 100644 index f3dc576..0000000 Binary files a/host/libs/otel-dc-0.9.9.jar and /dev/null differ diff --git a/internal/otel-dc/build.gradle b/internal/otel-dc/build.gradle index 9cdcb90..717fed0 100644 --- a/internal/otel-dc/build.gradle +++ b/internal/otel-dc/build.gradle @@ -4,7 +4,7 @@ plugins { } group = "com.instana.dc" -version = "0.9.9" +version = "0.10.0" repositories { mavenCentral() diff --git a/internal/otel-dc/src/main/java/com/instana/dc/AbstractDc.java b/internal/otel-dc/src/main/java/com/instana/dc/AbstractDc.java index 9e78897..25a9be9 100644 --- a/internal/otel-dc/src/main/java/com/instana/dc/AbstractDc.java +++ b/internal/otel-dc/src/main/java/com/instana/dc/AbstractDc.java @@ -1,5 +1,12 @@ package com.instana.dc; +import java.time.Duration; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.TimeUnit; + +import static com.instana.dc.DcUtil.getCert; + import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.api.metrics.Meter; import io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporter; @@ -10,13 +17,6 @@ import io.opentelemetry.sdk.metrics.export.PeriodicMetricReader; import io.opentelemetry.sdk.resources.Resource; -import java.time.Duration; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.TimeUnit; - -import static com.instana.dc.DcUtil.getCert; - public abstract class AbstractDc implements IDc { private final Map meters = new ConcurrentHashMap<>(); private final Map rawMetricsMap; @@ -63,8 +63,10 @@ public static OtlpGrpcMetricExporter createOtlpGrpcMetricExporter(String otelBac .setEndpoint(otelBackendUrl) .setTimeout(timeout, TimeUnit.SECONDS); + HeadersSupplier supplier = HeadersSupplier.INSTANCE; + builder.setHeaders(supplier::getHeaders); if (headers != null) { - builder.setHeaders(() -> headers); + supplier.updateHeaders(headers); } if (cert != null) { builder.setTrustedCertificates(cert); @@ -78,8 +80,10 @@ public static OtlpHttpMetricExporter createOtlpHttpMetricExporter(String otelBac .setEndpoint(otelBackendUrl) .setTimeout(timeout, TimeUnit.SECONDS); + HeadersSupplier supplier = HeadersSupplier.INSTANCE; + builder.setHeaders(supplier::getHeaders); if (headers != null) { - builder.setHeaders(() -> headers); + supplier.updateHeaders(headers); } if (cert != null) { builder.setTrustedCertificates(cert); diff --git a/internal/otel-dc/src/main/java/com/instana/dc/HeadersSupplier.java b/internal/otel-dc/src/main/java/com/instana/dc/HeadersSupplier.java new file mode 100644 index 0000000..8d58572 --- /dev/null +++ b/internal/otel-dc/src/main/java/com/instana/dc/HeadersSupplier.java @@ -0,0 +1,23 @@ +/* + * (c) Copyright IBM Corp. 2024 + * (c) Copyright Instana Inc. + */ +package com.instana.dc; + +import java.util.HashMap; +import java.util.Map; + +public enum HeadersSupplier { + INSTANCE; + + private final Map headers = new HashMap<>(); + + public synchronized void updateHeaders(Map newHeaders) { + headers.clear(); + headers.putAll(newHeaders); + } + + public Map getHeaders() { + return new HashMap<>(headers); + } +} diff --git a/llm/build.gradle b/llm/build.gradle index b9c9e8a..3025a2e 100644 --- a/llm/build.gradle +++ b/llm/build.gradle @@ -27,7 +27,7 @@ dependencies { implementation("com.google.protobuf:protobuf-java-util:3.23.4") implementation("com.linecorp.armeria:armeria:1.27.3") implementation("com.linecorp.armeria:armeria-grpc:1.27.3") - implementation(files("libs/otel-dc-0.9.9.jar")) + implementation(files("libs/otel-dc-0.10.0.jar")) testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.1") testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.1") diff --git a/llm/libs/otel-dc-0.10.0.jar b/llm/libs/otel-dc-0.10.0.jar new file mode 100644 index 0000000..19c967c Binary files /dev/null and b/llm/libs/otel-dc-0.10.0.jar differ diff --git a/llm/libs/otel-dc-0.9.9.jar b/llm/libs/otel-dc-0.9.9.jar deleted file mode 100644 index f3dc576..0000000 Binary files a/llm/libs/otel-dc-0.9.9.jar and /dev/null differ diff --git a/llm/src/main/java/com/instana/dc/llm/impl/llm/MetricsCollectorService.java b/llm/src/main/java/com/instana/dc/llm/impl/llm/MetricsCollectorService.java index 32e42eb..b39c4ea 100644 --- a/llm/src/main/java/com/instana/dc/llm/impl/llm/MetricsCollectorService.java +++ b/llm/src/main/java/com/instana/dc/llm/impl/llm/MetricsCollectorService.java @@ -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; @@ -190,6 +197,26 @@ public void export( ExportMetricsServiceRequest request, StreamObserver 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 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 allResourceMetrics = request.getResourceMetricsList(); for (ResourceMetrics resourceMetrics : allResourceMetrics) { diff --git a/rdb/build.gradle b/rdb/build.gradle index 6955260..d464079 100644 --- a/rdb/build.gradle +++ b/rdb/build.gradle @@ -20,7 +20,7 @@ dependencies { implementation("io.opentelemetry:opentelemetry-exporter-sender-okhttp:1.34.1") implementation("io.opentelemetry.semconv:opentelemetry-semconv:1.23.1-alpha") implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.16.0-rc1") - implementation(files("libs/otel-dc-0.9.9.jar")) + implementation(files("libs/otel-dc-0.10.0.jar")) implementation(files("libs/ngdbc-2.4.64.jar")) implementation("org.apache.commons:commons-dbcp2:2.11.0") diff --git a/rdb/libs/otel-dc-0.10.0.jar b/rdb/libs/otel-dc-0.10.0.jar new file mode 100644 index 0000000..19c967c Binary files /dev/null and b/rdb/libs/otel-dc-0.10.0.jar differ diff --git a/rdb/libs/otel-dc-0.9.9.jar b/rdb/libs/otel-dc-0.9.9.jar deleted file mode 100644 index f3dc576..0000000 Binary files a/rdb/libs/otel-dc-0.9.9.jar and /dev/null differ