Skip to content

Commit 4529996

Browse files
author
Ignacio Bonafonte
authored
Datadog exporter: Add a config setting to avoid exporting unsampled spans or logs from unsampled spans (#77)
1 parent f817d11 commit 4529996

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

Sources/Exporters/DatadogExporter/DatadogExporter.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@ public class DatadogExporter: SpanExporter {
3333

3434
public func export(spans: [SpanData]) -> SpanExporterResultCode {
3535
spans.forEach {
36-
spansExporter.exportSpan(span: $0)
37-
logsExporter.exportLogs(fromSpan: $0)
36+
if $0.traceFlags.sampled || configuration.exportUnsampledSpans {
37+
spansExporter.exportSpan(span: $0)
38+
}
39+
if $0.traceFlags.sampled || configuration.exportUnsampledLogs {
40+
logsExporter.exportLogs(fromSpan: $0)
41+
}
3842
}
3943
return .success
4044
}

Sources/Exporters/DatadogExporter/ExporterConfiguration.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,13 @@ public struct ExporterConfiguration {
3232
var uploadCondition: () -> Bool
3333
/// Performance preset for reporting
3434
var performancePreset: PerformancePreset = .default
35+
/// Option to export spans that have TraceFlag off, true by default
36+
var exportUnsampledSpans: Bool = true
37+
/// Option to export logs from spans that have TraceFlag off, true by default
38+
var exportUnsampledLogs: Bool = true
3539

36-
public init(serviceName: String, resource: String, applicationName: String, applicationVersion: String, environment: String, clientToken: String, endpoint: Endpoint, uploadCondition: @escaping () -> Bool, performancePreset: PerformancePreset = .default) {
40+
41+
public init(serviceName: String, resource: String, applicationName: String, applicationVersion: String, environment: String, clientToken: String, endpoint: Endpoint, uploadCondition: @escaping () -> Bool, performancePreset: PerformancePreset = .default, exportUnsampledSpans: Bool = true, exportUnsampledLogs: Bool = true ) {
3742
self.serviceName = serviceName
3843
self.resource = resource
3944
self.applicationName = applicationName
@@ -43,5 +48,7 @@ public struct ExporterConfiguration {
4348
self.endpoint = endpoint
4449
self.uploadCondition = uploadCondition
4550
self.performancePreset = performancePreset
51+
self.exportUnsampledSpans = exportUnsampledSpans
52+
self.exportUnsampledLogs = exportUnsampledLogs
4653
}
4754
}

0 commit comments

Comments
 (0)