Skip to content

Commit 9de824b

Browse files
authored
Store OTel scope/descriptor strings as UTF8BytesString to help with OTLP export (#10807)
Store OTel scope/descriptor strings as UTF8BytesString to help with OTLP export Co-authored-by: stuart.mcculloch <stuart.mcculloch@datadoghq.com>
1 parent 80f8f15 commit 9de824b

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-21
lines changed

dd-java-agent/agent-otel/otel-shim/src/main/java/datadog/opentelemetry/shim/OtelInstrumentationScope.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
11
package datadog.opentelemetry.shim;
22

3+
import datadog.trace.bootstrap.instrumentation.api.UTF8BytesString;
34
import java.util.Objects;
45
import javax.annotation.Nullable;
56

67
/** Instrumentation scopes have a mandatory name, optional version, and optional schema URL. */
78
public final class OtelInstrumentationScope {
89

9-
private final String scopeName;
10-
@Nullable private final String scopeVersion;
11-
@Nullable private final String schemaUrl;
10+
private final UTF8BytesString scopeName;
11+
@Nullable private final UTF8BytesString scopeVersion;
12+
@Nullable private final UTF8BytesString schemaUrl;
1213

1314
public OtelInstrumentationScope(
1415
String scopeName, @Nullable String scopeVersion, @Nullable String schemaUrl) {
15-
this.scopeName = scopeName;
16-
this.scopeVersion = scopeVersion;
17-
this.schemaUrl = schemaUrl;
16+
this.scopeName = UTF8BytesString.create(scopeName);
17+
this.scopeVersion = UTF8BytesString.create(scopeVersion);
18+
this.schemaUrl = UTF8BytesString.create(schemaUrl);
1819
}
1920

20-
public String getName() {
21+
public UTF8BytesString getName() {
2122
return scopeName;
2223
}
2324

2425
@Nullable
25-
public String getVersion() {
26+
public UTF8BytesString getVersion() {
2627
return scopeVersion;
2728
}
2829

2930
@Nullable
30-
public String getSchemaUrl() {
31+
public UTF8BytesString getSchemaUrl() {
3132
return schemaUrl;
3233
}
3334

dd-java-agent/agent-otel/otel-shim/src/main/java/datadog/opentelemetry/shim/metrics/OtelInstrumentDescriptor.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
package datadog.opentelemetry.shim.metrics;
22

3+
import datadog.trace.bootstrap.instrumentation.api.UTF8BytesString;
34
import java.util.Locale;
45
import java.util.Objects;
56
import javax.annotation.Nullable;
67

78
/** Uniquely describes an instrument for the Meter that created it. */
89
public final class OtelInstrumentDescriptor {
9-
private final String instrumentName;
10+
private final UTF8BytesString instrumentName;
1011
private final OtelInstrumentType instrumentType;
1112
private final boolean longValues;
12-
@Nullable private final String description;
13-
@Nullable private final String unit;
13+
@Nullable private final UTF8BytesString description;
14+
@Nullable private final UTF8BytesString unit;
1415

1516
OtelInstrumentDescriptor(
1617
String instrumentName,
1718
OtelInstrumentType instrumentType,
1819
boolean longValues,
1920
@Nullable String description,
2021
@Nullable String unit) {
21-
this.instrumentName = instrumentName;
22+
this.instrumentName = UTF8BytesString.create(instrumentName);
2223
this.instrumentType = instrumentType;
2324
this.longValues = longValues;
24-
this.description = description;
25-
this.unit = unit;
25+
this.description = UTF8BytesString.create(description);
26+
this.unit = UTF8BytesString.create(unit);
2627
}
2728

28-
public String getName() {
29+
public UTF8BytesString getName() {
2930
return instrumentName;
3031
}
3132

@@ -38,12 +39,12 @@ public boolean hasLongValues() {
3839
}
3940

4041
@Nullable
41-
public String getDescription() {
42+
public UTF8BytesString getDescription() {
4243
return description;
4344
}
4445

4546
@Nullable
46-
public String getUnit() {
47+
public UTF8BytesString getUnit() {
4748
return unit;
4849
}
4950

@@ -54,7 +55,7 @@ public boolean equals(Object o) {
5455
}
5556

5657
OtelInstrumentDescriptor that = (OtelInstrumentDescriptor) o;
57-
return instrumentName.equalsIgnoreCase(that.instrumentName)
58+
return instrumentName.toString().equalsIgnoreCase(that.instrumentName.toString())
5859
&& instrumentType == that.instrumentType
5960
&& longValues == that.longValues
6061
&& Objects.equals(description, that.description)
@@ -63,7 +64,7 @@ public boolean equals(Object o) {
6364

6465
@Override
6566
public int hashCode() {
66-
int result = instrumentName.toLowerCase(Locale.ROOT).hashCode();
67+
int result = instrumentName.toString().toLowerCase(Locale.ROOT).hashCode();
6768
result = 31 * result + instrumentType.hashCode();
6869
result = 31 * result + Boolean.hashCode(longValues);
6970
result = 31 * result + Objects.hashCode(description);

dd-java-agent/agent-otel/otel-shim/src/main/java/datadog/opentelemetry/shim/metrics/data/OtelMetricStorage.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import datadog.opentelemetry.shim.metrics.export.OtelInstrumentVisitor;
66
import datadog.trace.api.Config;
77
import datadog.trace.api.config.OtlpConfig;
8+
import datadog.trace.bootstrap.instrumentation.api.UTF8BytesString;
89
import datadog.trace.relocate.api.RatelimitedLogger;
910
import io.opentelemetry.api.common.Attributes;
1011
import java.util.List;
@@ -89,7 +90,7 @@ public static OtelMetricStorage newHistogramStorage(
8990
return new OtelMetricStorage(descriptor, () -> new OtelHistogramSketch(bucketBoundaries));
9091
}
9192

92-
public String getInstrumentName() {
93+
public UTF8BytesString getInstrumentName() {
9394
return descriptor.getName();
9495
}
9596

0 commit comments

Comments
 (0)