Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISSUE-1337 Add EntityID to DatadogAgentReporter #1338

Merged
merged 2 commits into from
May 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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