Skip to content

Commit

Permalink
Add headers supplier for DC exporter (#67)
Browse files Browse the repository at this point in the history
* Implement dynamic headers for exporter

* Pick up the latest otel-dc-0.10.0.jar
  • Loading branch information
jinsongo authored Nov 2, 2024
1 parent dd5acb5 commit 3caf966
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 13 deletions.
2 changes: 1 addition & 1 deletion host/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Binary file added host/libs/otel-dc-0.10.0.jar
Binary file not shown.
Binary file removed host/libs/otel-dc-0.9.9.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion internal/otel-dc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = "com.instana.dc"
version = "0.9.9"
version = "0.10.0"

repositories {
mavenCentral()
Expand Down
22 changes: 13 additions & 9 deletions internal/otel-dc/src/main/java/com/instana/dc/AbstractDc.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<String, Meter> meters = new ConcurrentHashMap<>();
private final Map<String, RawMetric> rawMetricsMap;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
23 changes: 23 additions & 0 deletions internal/otel-dc/src/main/java/com/instana/dc/HeadersSupplier.java
Original file line number Diff line number Diff line change
@@ -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<String, String> headers = new HashMap<>();

public synchronized void updateHeaders(Map<String, String> newHeaders) {
headers.clear();
headers.putAll(newHeaders);
}

public Map<String, String> getHeaders() {
return new HashMap<>(headers);
}
}
2 changes: 1 addition & 1 deletion llm/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Binary file added llm/libs/otel-dc-0.10.0.jar
Binary file not shown.
Binary file removed llm/libs/otel-dc-0.9.9.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion rdb/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
Binary file added rdb/libs/otel-dc-0.10.0.jar
Binary file not shown.
Binary file removed rdb/libs/otel-dc-0.9.9.jar
Binary file not shown.

0 comments on commit 3caf966

Please sign in to comment.