Skip to content

Commit 089f5c6

Browse files
author
Ignacio Bonafonte
authored
Datadog exporter: Export resource.name properly and filter the tag for later exporting (#252)
1 parent eec1f8f commit 089f5c6

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

Examples/Datadog Sample/main.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import UIKit
1313

1414
let apikeyOrClientToken = ""
1515

16+
let resourceKey = "resource.name"
17+
let resourceValue = "The resource"
18+
1619
let sampleKey = "sampleKey"
1720
let sampleValue = "sampleValue"
1821

@@ -60,7 +63,7 @@ func testTraces() {
6063

6164
func simpleSpan() {
6265
let span = tracer.spanBuilder(spanName: "SimpleSpan").setSpanKind(spanKind: .client).startSpan()
63-
span.setAttribute(key: sampleKey, value: sampleValue)
66+
span.setAttribute(key: resourceKey, value: resourceValue)
6467
span.addEvent(name: "My event", attributes: ["message": AttributeValue.string("test message"),
6568
"newKey": AttributeValue.string("New Value")])
6669
span.end()

Sources/Exporters/DatadogExporter/Spans/SpanEncoder.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ internal struct DDSpan: Encodable {
5757
/// Custom tags, received from user
5858
let tags: [String: AttributeValue]
5959

60-
static let errorTagKeys: Set<String> = [
61-
"error.message", "error.type", "error.stack",
60+
static let filteredTagKeys: Set<String> = [
61+
"error.message", "error.type", "error.stack", "resource.name"
6262
]
6363

6464
func encode(to encoder: Encoder) throws {
@@ -77,7 +77,7 @@ internal struct DDSpan: Encodable {
7777
}
7878

7979
self.serviceName = configuration.serviceName
80-
self.resource = spanData.name
80+
self.resource = spanData.attributes["resource.name"]?.description ?? spanData.name
8181
self.startTime = spanData.startTime.timeIntervalSince1970.toNanoseconds
8282
self.duration = spanData.endTime.timeIntervalSince(spanData.startTime).toNanoseconds
8383

@@ -99,7 +99,7 @@ internal struct DDSpan: Encodable {
9999

100100
self.applicationVersion = configuration.version
101101
self.tags = spanData.attributes.filter {
102-
!DDSpan.errorTagKeys.contains($0.key)
102+
!DDSpan.filteredTagKeys.contains($0.key)
103103
}.mapValues { $0 }
104104
}
105105
}

0 commit comments

Comments
 (0)