forked from open-telemetry/opentelemetry-java
-
Notifications
You must be signed in to change notification settings - Fork 1
/
OtlpUserAgent.java
55 lines (47 loc) · 1.63 KB
/
OtlpUserAgent.java
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.exporter.internal.otlp;
import java.util.Properties;
import java.util.function.BiConsumer;
/**
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
* any time.
*/
public final class OtlpUserAgent {
private static final String userAgent = "OTel OTLP Exporter Java/" + readVersion();
private static String readVersion() {
Properties properties = new Properties();
try {
properties.load(OtlpUserAgent.class.getResourceAsStream("version.properties"));
} catch (Exception e) {
// we left the attribute empty
return "unknown";
}
return properties.getProperty("sdk.version", "unknown");
}
/**
* Return an OTLP {@code User-Agent} header value of the form {@code "OTel OTLP Exporter
* Java/{version}"}.
*
* @see <a
* href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md#user-agent">OTLP
* Exporter User Agent</a>
*/
public static String getUserAgent() {
return userAgent;
}
/**
* Call the {@code consumer with} an OTLP {@code User-Agent} header value of the form {@code "OTel
* OTLP Exporter Java/{version}"}.
*
* @see <a
* href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md#user-agent">OTLP
* Exporter User Agent</a>
*/
public static void addUserAgentHeader(BiConsumer<String, String> consumer) {
consumer.accept("User-Agent", userAgent);
}
private OtlpUserAgent() {}
}