Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
bryce-b committed Sep 21, 2023
1 parent c0cd7d3 commit 4521fbe
Show file tree
Hide file tree
Showing 47 changed files with 2,085 additions and 2,049 deletions.
6 changes: 3 additions & 3 deletions Sources/Exporters/DatadogExporter/DatadogExporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class DatadogExporter: SpanExporter, MetricExporter {
metricsExporter = try MetricsExporter(config: configuration)
}

public func export(spans: [SpanData]) -> SpanExporterResultCode {
public func export(spans: [SpanData], explicitTimeout: TimeInterval?) -> SpanExporterResultCode {
spans.forEach {
if $0.traceFlags.sampled || configuration.exportUnsampledSpans {
spansExporter?.exportSpan(span: $0)
Expand All @@ -38,7 +38,7 @@ public class DatadogExporter: SpanExporter, MetricExporter {
return .success
}

public func flush() -> SpanExporterResultCode {
public func flush(explicitTimeout: TimeInterval?) -> SpanExporterResultCode {
spansExporter?.tracesStorage.writer.queue.sync {}
logsExporter?.logsStorage.writer.queue.sync {}
metricsExporter?.metricsStorage.writer.queue.sync {}
Expand All @@ -49,7 +49,7 @@ public class DatadogExporter: SpanExporter, MetricExporter {
return .success
}

public func shutdown() {
public func shutdown(explicitTimeout: TimeInterval?) {
_ = self.flush()
}

Expand Down
64 changes: 32 additions & 32 deletions Sources/Exporters/InMemory/InMemoryExporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,38 @@ import Foundation
import OpenTelemetrySdk

public class InMemoryExporter: SpanExporter {
private var finishedSpanItems: [SpanData] = []
private var isRunning: Bool = true

public init() {}

public func getFinishedSpanItems() -> [SpanData] {
return finishedSpanItems
}

public func export(spans: [SpanData], explicitTimeout: TimeInterval?) -> SpanExporterResultCode {
guard isRunning else {
return .failure
}

finishedSpanItems.append(contentsOf: spans)
return .success
private var finishedSpanItems: [SpanData] = []
private var isRunning: Bool = true

public init() {}

public func getFinishedSpanItems() -> [SpanData] {
return finishedSpanItems
}

public func export(spans: [SpanData], explicitTimeout: TimeInterval? = nil) -> SpanExporterResultCode {
guard isRunning else {
return .failure
}

public func flush(explicitTimeout: TimeInterval?) -> SpanExporterResultCode {
guard isRunning else {
return .failure
}

return .success
}

public func reset() {
finishedSpanItems.removeAll()
}

public func shutdown(explicitTimeout: TimeInterval?) {
finishedSpanItems.removeAll()
isRunning = false

finishedSpanItems.append(contentsOf: spans)
return .success
}

public func flush(explicitTimeout: TimeInterval? = nil) -> SpanExporterResultCode {
guard isRunning else {
return .failure
}

return .success
}

public func reset() {
finishedSpanItems.removeAll()
}

public func shutdown(explicitTimeout: TimeInterval? = nil) {
finishedSpanItems.removeAll()
isRunning = false
}
}
44 changes: 22 additions & 22 deletions Sources/Exporters/Jaeger/JaegerSpanExporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@ import OpenTelemetrySdk
import Thrift

public class JaegerSpanExporter: SpanExporter {
let collectorAddress: String
let process: Process

public init(serviceName: String, collectorAddress: String) {
process = Process(serviceName: serviceName, tags: TList<Tag>())
self.collectorAddress = collectorAddress
}

public func export(spans: [SpanData], explicitTimeout: TimeInterval?) -> SpanExporterResultCode {
var spanList = TList<Span>()
spanList.append(contentsOf: Adapter.toJaeger(spans: spans))
let batch = Batch(process: process, spans: spanList)
let collectorAddress: String
let process: Process
public init(serviceName: String, collectorAddress: String) {
process = Process(serviceName: serviceName, tags: TList<Tag>())
self.collectorAddress = collectorAddress
}

Check warning on line 19 in Sources/Exporters/Jaeger/JaegerSpanExporter.swift

View check run for this annotation

Codecov / codecov/patch

Sources/Exporters/Jaeger/JaegerSpanExporter.swift#L16-L19

Added lines #L16 - L19 were not covered by tests
public func export(spans: [SpanData], explicitTimeout: TimeInterval? = nil) -> SpanExporterResultCode {
var spanList = TList<Span>()
spanList.append(contentsOf: Adapter.toJaeger(spans: spans))
let batch = Batch(process: process, spans: spanList)
let sender = Sender(host: collectorAddress)
let success = sender.sendBatch(batch: batch)
return success ? SpanExporterResultCode.success : SpanExporterResultCode.failure
}

public func flush(explicitTimeout: TimeInterval?) -> SpanExporterResultCode {
return .success
}

public func shutdown(explicitTimeout: TimeInterval?) {
}
let success = sender.sendBatch(batch: batch)
return success ? SpanExporterResultCode.success : SpanExporterResultCode.failure
}

Check warning on line 28 in Sources/Exporters/Jaeger/JaegerSpanExporter.swift

View check run for this annotation

Codecov / codecov/patch

Sources/Exporters/Jaeger/JaegerSpanExporter.swift#L21-L28

Added lines #L21 - L28 were not covered by tests
public func flush(explicitTimeout: TimeInterval? = nil) -> SpanExporterResultCode {
return .success
}

Check warning on line 32 in Sources/Exporters/Jaeger/JaegerSpanExporter.swift

View check run for this annotation

Codecov / codecov/patch

Sources/Exporters/Jaeger/JaegerSpanExporter.swift#L30-L32

Added lines #L30 - L32 were not covered by tests
public func shutdown(explicitTimeout: TimeInterval? = nil) {
}

Check warning on line 35 in Sources/Exporters/Jaeger/JaegerSpanExporter.swift

View check run for this annotation

Codecov / codecov/patch

Sources/Exporters/Jaeger/JaegerSpanExporter.swift#L34-L35

Added lines #L34 - L35 were not covered by tests
}

#endif
102 changes: 51 additions & 51 deletions Sources/Exporters/OpenTelemetryProtocolGrpc/logs/OtlpLogExporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,59 +13,59 @@ import OpenTelemetrySdk
import OpenTelemetryProtocolExporterCommon

public class OtlpLogExporter : LogRecordExporter {
let channel : GRPCChannel
var logClient : Opentelemetry_Proto_Collector_Logs_V1_LogsServiceNIOClient
let config : OtlpConfiguration
var callOptions : CallOptions

public init(channel: GRPCChannel,
config: OtlpConfiguration = OtlpConfiguration(),
logger: Logging.Logger = Logging.Logger(label: "io.grpc", factory: { _ in SwiftLogNoOpLogHandler() }),
envVarHeaders: [(String, String)]? = EnvVarHeaders.attributes){
self.channel = channel
logClient = Opentelemetry_Proto_Collector_Logs_V1_LogsServiceNIOClient(channel: channel)
self.config = config
let userAgentHeader = (Constants.HTTP.userAgent, Headers.getUserAgentHeader())
if let headers = envVarHeaders {
var updatedHeaders = headers
updatedHeaders.append(userAgentHeader)
callOptions = CallOptions(customMetadata: HPACKHeaders(updatedHeaders), logger: logger)
} else if let headers = config.headers {
var updatedHeaders = headers
updatedHeaders.append(userAgentHeader)
callOptions = CallOptions(customMetadata: HPACKHeaders(updatedHeaders), logger: logger)
}
else {
var headers = [(String, String)]()
headers.append(userAgentHeader)
callOptions = CallOptions(customMetadata: HPACKHeaders(headers), logger: logger)
}
let channel : GRPCChannel
var logClient : Opentelemetry_Proto_Collector_Logs_V1_LogsServiceNIOClient
let config : OtlpConfiguration
var callOptions : CallOptions

public init(channel: GRPCChannel,
config: OtlpConfiguration = OtlpConfiguration(),
logger: Logging.Logger = Logging.Logger(label: "io.grpc", factory: { _ in SwiftLogNoOpLogHandler() }),
envVarHeaders: [(String, String)]? = EnvVarHeaders.attributes){
self.channel = channel
logClient = Opentelemetry_Proto_Collector_Logs_V1_LogsServiceNIOClient(channel: channel)
self.config = config
let userAgentHeader = (Constants.HTTP.userAgent, Headers.getUserAgentHeader())
if let headers = envVarHeaders {
var updatedHeaders = headers
updatedHeaders.append(userAgentHeader)
callOptions = CallOptions(customMetadata: HPACKHeaders(updatedHeaders), logger: logger)
} else if let headers = config.headers {
var updatedHeaders = headers
updatedHeaders.append(userAgentHeader)
callOptions = CallOptions(customMetadata: HPACKHeaders(updatedHeaders), logger: logger)
}

public func export(logRecords: [ReadableLogRecord], explicitTimeout: TimeInterval?) -> ExportResult {
let logRequest = Opentelemetry_Proto_Collector_Logs_V1_ExportLogsServiceRequest.with { request in
request.resourceLogs = LogRecordAdapter.toProtoResourceRecordLog(logRecordList: logRecords)
}
let timeout = min(explicitTimeout ?? TimeInterval.greatestFiniteMagnitude, config.timeout)
if timeout > 0 {
callOptions.timeLimit = TimeLimit.timeout(TimeAmount.nanoseconds(Int64(timeout.toNanoseconds)))
}


let export = logClient.export(logRequest, callOptions: callOptions)
do {
_ = try export.response.wait()
return .success
} catch {
return .failure
}
else {
var headers = [(String, String)]()
headers.append(userAgentHeader)
callOptions = CallOptions(customMetadata: HPACKHeaders(headers), logger: logger)
}

public func shutdown(explicitTimeout: TimeInterval?) {
_ = channel.close()
}

public func export(logRecords: [ReadableLogRecord], explicitTimeout: TimeInterval? = nil) -> ExportResult {
let logRequest = Opentelemetry_Proto_Collector_Logs_V1_ExportLogsServiceRequest.with { request in
request.resourceLogs = LogRecordAdapter.toProtoResourceRecordLog(logRecordList: logRecords)
}

public func forceFlush(explicitTimeout: TimeInterval?) -> ExportResult {
.success
let timeout = min(explicitTimeout ?? TimeInterval.greatestFiniteMagnitude, config.timeout)
if timeout > 0 {
callOptions.timeLimit = TimeLimit.timeout(TimeAmount.nanoseconds(Int64(timeout.toNanoseconds)))
}


let export = logClient.export(logRequest, callOptions: callOptions)
do {
_ = try export.response.wait()
return .success
} catch {
return .failure
}
}

public func shutdown(explicitTimeout: TimeInterval? = nil) {
_ = channel.close()
}

public func forceFlush(explicitTimeout: TimeInterval? = nil) -> ExportResult {
.success
}

Check warning on line 70 in Sources/Exporters/OpenTelemetryProtocolGrpc/logs/OtlpLogExporter.swift

View check run for this annotation

Codecov / codecov/patch

Sources/Exporters/OpenTelemetryProtocolGrpc/logs/OtlpLogExporter.swift#L68-L70

Added lines #L68 - L70 were not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,57 +14,57 @@ import OpenTelemetryProtocolExporterCommon

public class OtlpTraceExporter: SpanExporter {

let channel: GRPCChannel
var traceClient: Opentelemetry_Proto_Collector_Trace_V1_TraceServiceNIOClient
let config : OtlpConfiguration
var callOptions : CallOptions

public init(channel: GRPCChannel, config: OtlpConfiguration = OtlpConfiguration(), logger: Logging.Logger = Logging.Logger(label: "io.grpc", factory: { _ in SwiftLogNoOpLogHandler() }), envVarHeaders: [(String,String)]? = EnvVarHeaders.attributes) {
self.channel = channel
traceClient = Opentelemetry_Proto_Collector_Trace_V1_TraceServiceNIOClient(channel: channel)
self.config = config
let userAgentHeader = (Constants.HTTP.userAgent, Headers.getUserAgentHeader())
if let headers = envVarHeaders {
var updatedHeaders = headers
updatedHeaders.append(userAgentHeader)
callOptions = CallOptions(customMetadata: HPACKHeaders(updatedHeaders), logger: logger)
} else if let headers = config.headers {
var updatedHeaders = headers
updatedHeaders.append(userAgentHeader)
callOptions = CallOptions(customMetadata: HPACKHeaders(updatedHeaders), logger: logger)
} else {
var headers = [(String, String)]()
headers.append(userAgentHeader)
callOptions = CallOptions(customMetadata: HPACKHeaders(headers), logger: logger)
}
let channel: GRPCChannel
var traceClient: Opentelemetry_Proto_Collector_Trace_V1_TraceServiceNIOClient
let config : OtlpConfiguration
var callOptions : CallOptions

public init(channel: GRPCChannel, config: OtlpConfiguration = OtlpConfiguration(), logger: Logging.Logger = Logging.Logger(label: "io.grpc", factory: { _ in SwiftLogNoOpLogHandler() }), envVarHeaders: [(String,String)]? = EnvVarHeaders.attributes) {
self.channel = channel
traceClient = Opentelemetry_Proto_Collector_Trace_V1_TraceServiceNIOClient(channel: channel)
self.config = config
let userAgentHeader = (Constants.HTTP.userAgent, Headers.getUserAgentHeader())
if let headers = envVarHeaders {
var updatedHeaders = headers
updatedHeaders.append(userAgentHeader)
callOptions = CallOptions(customMetadata: HPACKHeaders(updatedHeaders), logger: logger)
} else if let headers = config.headers {
var updatedHeaders = headers
updatedHeaders.append(userAgentHeader)
callOptions = CallOptions(customMetadata: HPACKHeaders(updatedHeaders), logger: logger)
} else {
var headers = [(String, String)]()
headers.append(userAgentHeader)
callOptions = CallOptions(customMetadata: HPACKHeaders(headers), logger: logger)
}


}


public func export(spans: [SpanData], explicitTimeout: TimeInterval? = nil) -> SpanExporterResultCode {
let exportRequest = Opentelemetry_Proto_Collector_Trace_V1_ExportTraceServiceRequest.with {
$0.resourceSpans = SpanAdapter.toProtoResourceSpans(spanDataList: spans)
}
let timeout = min(explicitTimeout ?? TimeInterval.greatestFiniteMagnitude, config.timeout)
if timeout > 0 {
callOptions.timeLimit = TimeLimit.timeout(TimeAmount.nanoseconds(Int64(timeout.toNanoseconds)))
}

let export = traceClient.export(exportRequest, callOptions: callOptions)

do {
// wait() on the response to stop the program from exiting before the response is received.
_ = try export.response.wait()
return .success
} catch {
return .failure
}
}

public func flush(explicitTimeout: TimeInterval?) -> SpanExporterResultCode {
return .success
if timeout > 0 {
callOptions.timeLimit = TimeLimit.timeout(TimeAmount.nanoseconds(Int64(timeout.toNanoseconds)))
}

public func shutdown(explicitTimeout: TimeInterval?) {
_ = channel.close()

let export = traceClient.export(exportRequest, callOptions: callOptions)

do {
// wait() on the response to stop the program from exiting before the response is received.
_ = try export.response.wait()
return .success
} catch {
return .failure
}
}

public func flush(explicitTimeout: TimeInterval? = nil) -> SpanExporterResultCode {
return .success
}

Check warning on line 65 in Sources/Exporters/OpenTelemetryProtocolGrpc/trace/OtlpTraceExporter.swift

View check run for this annotation

Codecov / codecov/patch

Sources/Exporters/OpenTelemetryProtocolGrpc/trace/OtlpTraceExporter.swift#L63-L65

Added lines #L63 - L65 were not covered by tests

public func shutdown(explicitTimeout: TimeInterval? = nil) {
_ = channel.close()
}
}
Loading

0 comments on commit 4521fbe

Please sign in to comment.