Skip to content

Commit 9f403ac

Browse files
author
Ignacio Bonafonte
authored
Merge branch 'main' into fix-SPM-include-warnings
2 parents aee7b07 + 67d27f5 commit 9f403ac

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

Examples/Datadog Sample/main.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ tracer = OpenTelemetrySDK.instance.tracerProvider.get(instrumentationName: instr
3434
let exporterConfiguration = ExporterConfiguration(
3535
serviceName: "Opentelemetry exporter Example",
3636
resource: "Opentelemetry exporter",
37-
applicationName: "SimpleExample",
37+
applicationName: "SwiftDatadogSample",
3838
applicationVersion: "1.0.0",
3939
environment: "test",
4040
clientToken: clientKey,
@@ -64,7 +64,8 @@ func testTraces() {
6464
func simpleSpan() {
6565
let span = tracer.spanBuilder(spanName: "SimpleSpan").setSpanKind(spanKind: .client).startSpan()
6666
span.setAttribute(key: sampleKey, value: sampleValue)
67-
span.addEvent(name: "My event", attributes: ["message": AttributeValue.string("test message")])
67+
span.addEvent(name: "My event", attributes: ["message": AttributeValue.string("test message"),
68+
"newKey": AttributeValue.string("New Value")])
6869
span.end()
6970
}
7071

Sources/Exporters/DatadogExporter/Logs/LogEncoder.swift

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,27 @@ internal struct DDLog: Encodable {
9090
self.threadName = attributes.removeValue(forKey: "threadName")?.description ?? "unkown"
9191
self.applicationVersion = configuration.version
9292

93-
self.attributes = LogAttributes(userAttributes: event.attributes, internalAttributes: internalAttributes)
93+
let userAttributes: [String: Encodable] = attributes.mapValues{
94+
switch $0 {
95+
case let .string(value):
96+
return value
97+
case let .bool(value):
98+
return value
99+
case let .int(value):
100+
return value
101+
case let .double(value):
102+
return value
103+
case let .stringArray(value):
104+
return value
105+
case let .boolArray(value):
106+
return value
107+
case let .intArray(value):
108+
return value
109+
case let .doubleArray(value):
110+
return value
111+
}
112+
}
113+
self.attributes = LogAttributes(userAttributes: userAttributes, internalAttributes: internalAttributes)
94114
self.tags = nil // tags
95115
}
96116
}

Tests/ExportersTests/DatadogExporter/Logs/LogsExporterTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class LogsExporterTests: XCTestCase {
8585
name: "spanName",
8686
kind: .server,
8787
startTime: Date(timeIntervalSinceReferenceDate: 3000),
88-
events: [SpanData.Event(name: "event", timestamp: Date())],
88+
events: [SpanData.Event(name: "event", timestamp: Date(), attributes:["attributeKey": AttributeValue.string("attributeValue")])],
8989
endTime: Date(timeIntervalSinceReferenceDate: 3001),
9090
hasRemoteParent: false)
9191
}

0 commit comments

Comments
 (0)