Avoid conflicts in Micrometer description mapping (#5452)
* Avoid conflicts in Micrometer description mapping Signed-off-by: Fabian Stäber <fabian@fstab.de> * fix formatting * Update instrumentation/micrometer/micrometer-1.5/library/src/main/java/io/opentelemetry/instrumentation/micrometer/v1_5/Bridging.java Co-authored-by: Mateusz Rzeszutek <mrzeszutek@splunk.com> Co-authored-by: Mateusz Rzeszutek <mrzeszutek@splunk.com>
This commit is contained in:
parent
4a98dae431
commit
b6a5f2876b
|
@ -17,6 +17,7 @@ import io.opentelemetry.instrumentation.api.cache.Cache;
|
||||||
final class Bridging {
|
final class Bridging {
|
||||||
|
|
||||||
private static final Cache<String, AttributeKey<String>> tagsCache = Cache.bounded(1024);
|
private static final Cache<String, AttributeKey<String>> tagsCache = Cache.bounded(1024);
|
||||||
|
private static final Cache<String, String> descriptionsCache = Cache.bounded(1024);
|
||||||
|
|
||||||
static Attributes tagsAsAttributes(Meter.Id id, NamingConvention namingConvention) {
|
static Attributes tagsAsAttributes(Meter.Id id, NamingConvention namingConvention) {
|
||||||
Iterable<Tag> tags = id.getTagsAsIterable();
|
Iterable<Tag> tags = id.getTagsAsIterable();
|
||||||
|
@ -36,9 +37,14 @@ final class Bridging {
|
||||||
return namingConvention.name(id.getName(), id.getType(), id.getBaseUnit());
|
return namingConvention.name(id.getName(), id.getType(), id.getBaseUnit());
|
||||||
}
|
}
|
||||||
|
|
||||||
static String description(Meter.Id id) {
|
// TODO: remove the cache usage once the SDK is able to handle different descriptions
|
||||||
String description = id.getDescription();
|
static String description(String name, Meter.Id id) {
|
||||||
return description == null ? "" : description;
|
return descriptionsCache.computeIfAbsent(
|
||||||
|
name,
|
||||||
|
n -> {
|
||||||
|
String description = id.getDescription();
|
||||||
|
return description == null ? "" : description;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static String baseUnit(Meter.Id id) {
|
static String baseUnit(Meter.Id id) {
|
||||||
|
|
|
@ -34,10 +34,11 @@ final class OpenTelemetryCounter implements Counter, RemovableMeter {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
||||||
this.attributes = tagsAsAttributes(id, namingConvention);
|
this.attributes = tagsAsAttributes(id, namingConvention);
|
||||||
|
String conventionName = name(id, namingConvention);
|
||||||
this.otelCounter =
|
this.otelCounter =
|
||||||
otelMeter
|
otelMeter
|
||||||
.counterBuilder(name(id, namingConvention))
|
.counterBuilder(conventionName)
|
||||||
.setDescription(description(id))
|
.setDescription(description(conventionName, id))
|
||||||
.setUnit(baseUnit(id))
|
.setUnit(baseUnit(id))
|
||||||
.ofDoubles()
|
.ofDoubles()
|
||||||
.build();
|
.build();
|
||||||
|
|
|
@ -62,13 +62,13 @@ final class OpenTelemetryDistributionSummary extends AbstractDistributionSummary
|
||||||
this.otelHistogram =
|
this.otelHistogram =
|
||||||
otelMeter
|
otelMeter
|
||||||
.histogramBuilder(conventionName)
|
.histogramBuilder(conventionName)
|
||||||
.setDescription(description(id))
|
.setDescription(description(conventionName, id))
|
||||||
.setUnit(baseUnit(id))
|
.setUnit(baseUnit(id))
|
||||||
.build();
|
.build();
|
||||||
this.maxHandle =
|
this.maxHandle =
|
||||||
asyncInstrumentRegistry.buildGauge(
|
asyncInstrumentRegistry.buildGauge(
|
||||||
conventionName + ".max",
|
conventionName + ".max",
|
||||||
description(id),
|
description(conventionName, id),
|
||||||
baseUnit(id),
|
baseUnit(id),
|
||||||
attributes,
|
attributes,
|
||||||
max,
|
max,
|
||||||
|
|
|
@ -34,10 +34,11 @@ final class OpenTelemetryFunctionCounter<T> implements FunctionCounter, Removabl
|
||||||
AsyncInstrumentRegistry asyncInstrumentRegistry) {
|
AsyncInstrumentRegistry asyncInstrumentRegistry) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
||||||
|
String conventionName = name(id, namingConvention);
|
||||||
countMeasurementHandle =
|
countMeasurementHandle =
|
||||||
asyncInstrumentRegistry.buildDoubleCounter(
|
asyncInstrumentRegistry.buildDoubleCounter(
|
||||||
name(id, namingConvention),
|
conventionName,
|
||||||
description(id),
|
description(conventionName, id),
|
||||||
baseUnit(id),
|
baseUnit(id),
|
||||||
tagsAsAttributes(id, namingConvention),
|
tagsAsAttributes(id, namingConvention),
|
||||||
obj,
|
obj,
|
||||||
|
|
|
@ -45,18 +45,22 @@ final class OpenTelemetryFunctionTimer<T> implements FunctionTimer, RemovableMet
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.baseTimeUnit = baseTimeUnit;
|
this.baseTimeUnit = baseTimeUnit;
|
||||||
|
|
||||||
String countMeterName = name(id, namingConvention) + ".count";
|
String conventionName = name(id, namingConvention);
|
||||||
String totalTimeMeterName = name(id, namingConvention) + ".sum";
|
|
||||||
Attributes attributes = tagsAsAttributes(id, namingConvention);
|
Attributes attributes = tagsAsAttributes(id, namingConvention);
|
||||||
|
|
||||||
countMeasurementHandle =
|
countMeasurementHandle =
|
||||||
asyncInstrumentRegistry.buildLongCounter(
|
asyncInstrumentRegistry.buildLongCounter(
|
||||||
countMeterName, description(id), /* baseUnit = */ "1", attributes, obj, countFunction);
|
conventionName + ".count",
|
||||||
|
description(conventionName, id),
|
||||||
|
/* baseUnit = */ "1",
|
||||||
|
attributes,
|
||||||
|
obj,
|
||||||
|
countFunction);
|
||||||
|
|
||||||
totalTimeMeasurementHandle =
|
totalTimeMeasurementHandle =
|
||||||
asyncInstrumentRegistry.buildDoubleCounter(
|
asyncInstrumentRegistry.buildDoubleCounter(
|
||||||
totalTimeMeterName,
|
conventionName + ".sum",
|
||||||
description(id),
|
description(conventionName, id),
|
||||||
getUnitString(baseTimeUnit),
|
getUnitString(baseTimeUnit),
|
||||||
attributes,
|
attributes,
|
||||||
obj,
|
obj,
|
||||||
|
|
|
@ -35,10 +35,11 @@ final class OpenTelemetryGauge<T> implements Gauge, RemovableMeter {
|
||||||
|
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
||||||
|
String conventionName = name(id, namingConvention);
|
||||||
gaugeMeasurementHandle =
|
gaugeMeasurementHandle =
|
||||||
asyncInstrumentRegistry.buildGauge(
|
asyncInstrumentRegistry.buildGauge(
|
||||||
name(id, namingConvention),
|
conventionName,
|
||||||
description(id),
|
description(conventionName, id),
|
||||||
baseUnit(id),
|
baseUnit(id),
|
||||||
tagsAsAttributes(id, namingConvention),
|
tagsAsAttributes(id, namingConvention),
|
||||||
obj,
|
obj,
|
||||||
|
|
|
@ -43,7 +43,7 @@ final class OpenTelemetryLongTaskTimer extends DefaultLongTaskTimer implements R
|
||||||
this.activeTasksHandle =
|
this.activeTasksHandle =
|
||||||
asyncInstrumentRegistry.buildUpDownLongCounter(
|
asyncInstrumentRegistry.buildUpDownLongCounter(
|
||||||
conventionName + ".active",
|
conventionName + ".active",
|
||||||
description(id),
|
description(conventionName, id),
|
||||||
"tasks",
|
"tasks",
|
||||||
attributes,
|
attributes,
|
||||||
this,
|
this,
|
||||||
|
@ -51,7 +51,7 @@ final class OpenTelemetryLongTaskTimer extends DefaultLongTaskTimer implements R
|
||||||
this.durationHandle =
|
this.durationHandle =
|
||||||
asyncInstrumentRegistry.buildUpDownDoubleCounter(
|
asyncInstrumentRegistry.buildUpDownDoubleCounter(
|
||||||
conventionName + ".duration",
|
conventionName + ".duration",
|
||||||
description(id),
|
description(conventionName, id),
|
||||||
getUnitString(baseTimeUnit),
|
getUnitString(baseTimeUnit),
|
||||||
attributes,
|
attributes,
|
||||||
this,
|
this,
|
||||||
|
|
|
@ -39,7 +39,7 @@ final class OpenTelemetryMeter implements Meter, RemovableMeter {
|
||||||
List<AsyncMeasurementHandle> measurementHandles = new ArrayList<>();
|
List<AsyncMeasurementHandle> measurementHandles = new ArrayList<>();
|
||||||
for (Measurement measurement : measurements) {
|
for (Measurement measurement : measurements) {
|
||||||
String name = statisticInstrumentName(id, measurement.getStatistic(), namingConvention);
|
String name = statisticInstrumentName(id, measurement.getStatistic(), namingConvention);
|
||||||
String description = description(id);
|
String description = description(name, id);
|
||||||
String baseUnit = baseUnit(id);
|
String baseUnit = baseUnit(id);
|
||||||
|
|
||||||
switch (measurement.getStatistic()) {
|
switch (measurement.getStatistic()) {
|
||||||
|
|
|
@ -65,13 +65,13 @@ final class OpenTelemetryTimer extends AbstractTimer implements RemovableMeter {
|
||||||
this.otelHistogram =
|
this.otelHistogram =
|
||||||
otelMeter
|
otelMeter
|
||||||
.histogramBuilder(conventionName)
|
.histogramBuilder(conventionName)
|
||||||
.setDescription(description(id))
|
.setDescription(description(conventionName, id))
|
||||||
.setUnit(getUnitString(baseTimeUnit))
|
.setUnit(getUnitString(baseTimeUnit))
|
||||||
.build();
|
.build();
|
||||||
this.maxHandle =
|
this.maxHandle =
|
||||||
asyncInstrumentRegistry.buildGauge(
|
asyncInstrumentRegistry.buildGauge(
|
||||||
conventionName + ".max",
|
conventionName + ".max",
|
||||||
description(id),
|
description(conventionName, id),
|
||||||
getUnitString(baseTimeUnit),
|
getUnitString(baseTimeUnit),
|
||||||
attributes,
|
attributes,
|
||||||
max,
|
max,
|
||||||
|
|
Loading…
Reference in New Issue