Skip to content

Commit

Permalink
ISSUE-1337 Add EntityID to DatadogAgentReporter (#1338)
Browse files Browse the repository at this point in the history
* ISSUE-1337 Add EntityID to DatadogAgentReporter

* fix: EntityID could be provided from config, but for now only env supported
  • Loading branch information
juancarrey authored May 24, 2024
1 parent 7e31bad commit 09245ac
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class DatadogAgentReporter private[datadog] (@volatile private var config: Datad
new DecimalFormat("#.################################################################", symbols)
private val valueFormat = new DecimalFormat("#0.#########", symbols)

private val DD_ENTITY_ID_ENV_VAR = "DD_ENTITY_ID"
private val ENTITY_ID_TAG_NAME = "dd.internal.entity_id"

logger.info("Started the Kamon Datadog reporter")

override def stop(): Unit = {}
Expand All @@ -68,7 +71,7 @@ class DatadogAgentReporter private[datadog] (@volatile private var config: Datad
counter.name,
config.measurementFormatter.formatMeasurement(
encodeDatadogCounter(instrument.value, counter.settings.unit),
instrument.tags
updateTagsWithEntityID(instrument.tags)
)
)
}
Expand All @@ -81,7 +84,7 @@ class DatadogAgentReporter private[datadog] (@volatile private var config: Datad
gauge.name,
config.measurementFormatter.formatMeasurement(
encodeDatadogGauge(instrument.value, gauge.settings.unit),
instrument.tags
updateTagsWithEntityID(instrument.tags)
)
)
}
Expand All @@ -94,7 +97,7 @@ class DatadogAgentReporter private[datadog] (@volatile private var config: Datad

val bucketData = config.measurementFormatter.formatMeasurement(
encodeDatadogHistogramBucket(bucket.value, bucket.frequency, metric.settings.unit),
instruments.tags
updateTagsWithEntityID(instruments.tags)
)
config.packetBuffer.appendMeasurement(metric.name, bucketData)
}
Expand All @@ -103,6 +106,15 @@ class DatadogAgentReporter private[datadog] (@volatile private var config: Datad

}

private def updateTagsWithEntityID(tags: TagSet): TagSet = {
val entityId = System.getenv("DD_ENTITY_ID")
if (entityId != null && !entityId.trim().isEmpty()) {
return tags.withTag(ENTITY_ID_TAG_NAME, entityId);
}

return tags;
}

private def encodeDatadogHistogramBucket(value: Long, frequency: Long, unit: MeasurementUnit): String = {
val metricType = if (unit.dimension == Dimension.Time) "ms" else "h"
val samplingRate: Double = 1d / frequency.toDouble
Expand Down

0 comments on commit 09245ac

Please sign in to comment.