Skip to content

Commit 9991f56

Browse files
author
Ignacio Bonafonte
authored
Datadog Exporter: Export generic numeric tags under the metrics group. (#79)
1 parent 4529996 commit 9991f56

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

Sources/Exporters/DatadogExporter/Spans/SpanEncoder.swift

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ internal struct DDSpan: Encodable {
6969
// let userInfo: UserInfo
7070

7171
/// Custom tags, received from user
72-
let tags: [String: String]
72+
let tags: [String: AttributeValue]
7373

7474
static let errorTagKeys: Set<String> = [
7575
"error.message", "error.type", "error.stack",
@@ -114,9 +114,7 @@ internal struct DDSpan: Encodable {
114114
self.applicationVersion = "0.0.1" // spanData.applicationVersion
115115
self.tags = spanData.attributes.filter {
116116
!DDSpan.errorTagKeys.contains($0.key)
117-
}.mapValues {
118-
$0.description
119-
}
117+
}.mapValues { $0 }
120118
}
121119
}
122120

@@ -190,7 +188,7 @@ internal struct SpanEncoder {
190188
try encodeDefaultMeta(span, to: &container)
191189

192190
var customAttributesContainer = encoder.container(keyedBy: DynamicCodingKey.self)
193-
try encodeCustomMeta(span, to: &customAttributesContainer)
191+
try encodeCustomAttributes(span, to: &customAttributesContainer)
194192
}
195193

196194
/// Encodes default `metrics.*` attributes
@@ -211,11 +209,25 @@ internal struct SpanEncoder {
211209
}
212210

213211
/// Encodes `meta.*` attributes coming from user
214-
private func encodeCustomMeta(_ span: DDSpan, to container: inout KeyedEncodingContainer<DynamicCodingKey>) throws {
212+
private func encodeCustomAttributes(_ span: DDSpan, to container: inout KeyedEncodingContainer<DynamicCodingKey>) throws {
215213
// NOTE: RUMM-299 only string values are supported for `meta.*` attributes
216214
try span.tags.forEach {
217-
let metaKey = "meta.\($0.key)"
218-
try container.encode($0.value, forKey: DynamicCodingKey(metaKey))
215+
switch $0.value {
216+
case .int(let intValue):
217+
let metricsKey = "metrics.\($0.key)"
218+
try container.encode(intValue, forKey: DynamicCodingKey(metricsKey))
219+
case .double(let doubleValue):
220+
let metricsKey = "metrics.\($0.key)"
221+
try container.encode(doubleValue, forKey: DynamicCodingKey(metricsKey))
222+
case .string(let stringValue):
223+
let metaKey = "meta.\($0.key)"
224+
try container.encode(stringValue, forKey: DynamicCodingKey(metaKey))
225+
case .bool(let boolValue):
226+
let metaKey = "meta.\($0.key)"
227+
try container.encode(boolValue, forKey: DynamicCodingKey(metaKey))
228+
default:
229+
break
230+
}
219231
}
220232
}
221233
}

0 commit comments

Comments
 (0)