Skip to content

Commit

Permalink
Fix build warnings in our code (left some test warnings that are real) (
Browse files Browse the repository at this point in the history
#620)

Co-authored-by: Bryce Buchanan <75274611+bryce-b@users.noreply.github.com>
  • Loading branch information
nachoBonafonte and bryce-b authored Oct 28, 2024
1 parent 816c73e commit 31ba35e
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 20 deletions.
8 changes: 4 additions & 4 deletions Examples/ConcurrencyContext/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let sampleValue = "sampleValue"
// On Apple platforms, the default is the activity based context manager. We want to opt-in to the structured concurrency based context manager instead.
OpenTelemetry.registerDefaultConcurrencyContextManager()

let stdout = StdoutExporter()
let stdout = StdoutSpanExporter()
OpenTelemetry.registerTracerProvider(
tracerProvider: TracerProviderBuilder().add(
spanProcessor: SimpleSpanProcessor(spanExporter: stdout)
Expand All @@ -30,7 +30,7 @@ extension Task where Failure == Never, Success == Never {
}

func simpleSpan() async throws {
let span = tracer.spanBuilder(spanName: "SimpleSpan").setSpanKind(spanKind: .client).startSpan()
let span = await tracer.spanBuilder(spanName: "SimpleSpan").setSpanKind(spanKind: .client).startSpan()
span.setAttribute(key: sampleKey, value: sampleValue)
try await Task.sleep(seconds: 0.5)
span.end()
Expand All @@ -42,15 +42,15 @@ func childSpan() async throws {
span.setAttribute(key: sampleKey, value: sampleValue)
await Task.detached {
// A detached task doesn't inherit the task local context, so this span won't have a parent.
let notAChildSpan = tracer.spanBuilder(spanName: "notAChild").setSpanKind(spanKind: .client).startSpan()
let notAChildSpan = await tracer.spanBuilder(spanName: "notAChild").setSpanKind(spanKind: .client).startSpan()
notAChildSpan.setAttribute(key: sampleKey, value: sampleValue)
notAChildSpan.end()
}.value

try await Task {
// Normal tasks should still inherit the context.
try await Task.sleep(seconds: 0.2)
let childSpan = tracer.spanBuilder(spanName: "childSpan").setSpanKind(spanKind: .client).startSpan()
let childSpan = await tracer.spanBuilder(spanName: "childSpan").setSpanKind(spanKind: .client).startSpan()
childSpan.setAttribute(key: sampleKey, value: sampleValue)
try await Task.sleep(seconds: 0.5)
childSpan.end()
Expand Down
3 changes: 0 additions & 3 deletions Examples/Logs Sample/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ func configure() {
target: .hostAndPort("localhost", 4317),
eventLoopGroup: MultiThreadedEventLoopGroup(numberOfThreads: 1))


OtlpLogExporter(channel: ClientConnection(configuration: configuration))

OpenTelemetry.registerLoggerProvider(loggerProvider: LoggerProviderBuilder().with(processors: [
BatchLogRecordProcessor(logRecordExporter:OtlpLogExporter(channel: ClientConnection(configuration: configuration)))]).build())

Expand Down
2 changes: 1 addition & 1 deletion Examples/OTLP Exporter/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ let configuration = ClientConnection.Configuration.default(
let client = ClientConnection(configuration: configuration)

let otlpTraceExporter = OtlpTraceExporter(channel: client)
let stdoutExporter = StdoutExporter()
let stdoutExporter = StdoutSpanExporter()
let spanExporter = MultiSpanExporter(spanExporters: [otlpTraceExporter, stdoutExporter])

let spanProcessor = SimpleSpanProcessor(spanExporter: spanExporter)
Expand Down
2 changes: 1 addition & 1 deletion Examples/OTLP HTTP Exporter/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let instrumentationScopeName = "OTLPHTTPExporter"
let instrumentationScopeVersion = "semver:0.1.0"

let otlpHttpTraceExporter = OtlpHttpTraceExporter()
let stdoutExporter = StdoutExporter()
let stdoutExporter = StdoutSpanExporter()
let spanExporter = MultiSpanExporter(spanExporters: [otlpHttpTraceExporter, stdoutExporter])

let spanProcessor = SimpleSpanProcessor(spanExporter: spanExporter)
Expand Down
2 changes: 1 addition & 1 deletion Examples/Simple Exporter/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let instrumentationScopeVersion = "semver:0.1.0"
var tracer: TracerSdk
let jaegerCollectorAddress = "localhost"
let jaegerExporter = JaegerSpanExporter(serviceName: "SimpleExporter", collectorAddress: jaegerCollectorAddress)
let stdoutExporter = StdoutExporter()
let stdoutExporter = StdoutSpanExporter()

// let zipkinExporterOptions = ZipkinTraceExporterOptions()
// let zipkinExporter = ZipkinTraceExporter(options: zipkinExporterOptions)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Instrumentation/URLSession/URLSessionLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class URLSessionLogger {
}
instrumentation.configuration.injectCustomHeaders?(&request, span)
var instrumentedRequest = request
objc_setAssociatedObject(instrumentedRequest, &URLSessionInstrumentation.instrumentedKey, true, .OBJC_ASSOCIATION_COPY_NONATOMIC)
objc_setAssociatedObject(instrumentedRequest, URLSessionInstrumentation.instrumentedKey, true, .OBJC_ASSOCIATION_COPY_NONATOMIC)
let propagators = OpenTelemetry.instance.propagators
var traceHeaders = tracePropagationHTTPHeaders(span: span, textMapPropagator: propagators.textMapPropagator, textMapBaggagePropagator: propagators.textMapBaggagePropagator)
if let originalHeaders = request.allHTTPHeaderFields {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public class CallbackRegistration {
if !hasStorages {
return
}
for var measurement in observableMeasurements {
for measurement in observableMeasurements {
measurement.setActiveReader(reader: reader, startEpochNanos: startEpochNanos, epochNanos: epochNanos)
}
callback()
for var measurement in observableMeasurements {
for measurement in observableMeasurements {
measurement.clearActiveReader()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class AsynchronousMetricStorage: MetricStorage {
let newMeasurement = measurement.hasDoubleValue ? Measurement.doubleMeasurement(startEpochNano: start, endEpochNano: measurement.epochNano, value: measurement.doubleValue, attributes: processedAttributes) : Measurement.longMeasurement(startEpochNano: start, endEpochNano: measurement.epochNano, value: measurement.longValue, attributes: processedAttributes)
do {
try recordPoint(point: aggregator.toPoint(measurement: newMeasurement))
} catch let HistogramAggregatorError.unsupportedOperation(error) {
} catch HistogramAggregatorError.unsupportedOperation(_) {
// TODO: log error
} catch {
// TODO: log default error
Expand All @@ -65,7 +65,7 @@ public class AsynchronousMetricStorage: MetricStorage {
public func collect(resource: Resource, scope: InstrumentationScopeInfo, startEpochNanos: UInt64, epochNanos: UInt64) -> StableMetricData {
var result: [[String: AttributeValue]: PointData]
if aggregationTemporality == .delta {
var points = self.points
let points = self.points
var lastPoints = self.lastPoints
lastPoints = lastPoints.filter { element in
points[element.key] == nil // remove if points does not contain key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ class SpansExporterTests: XCTestCase {
}

func testWhenExportSpanIsCalled_thenTraceIsUploaded() throws {
#if os(watchOS)
throw XCTSkip("Test is flaky on watchOS")
#endif
throw XCTSkip("Skipped flaky test.")
var tracesSent = false
let expec = expectation(description: "traces received")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import OpenTelemetryProtocolExporterCommon
@testable import OpenTelemetrySdk
import XCTest

extension String: LocalizedError {
extension Swift.String: LocalizedError {
public var errorDescription: String? { return self }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class BatchLogRecordProcessorTests : XCTestCase {
for _ in 0 ..< 100 {
logger.logRecordBuilder().emit()
}
_ = processor.forceFlush()
processor.forceFlush()
let exported = waitingExporter.waitForExport()
XCTAssertEqual(exported?.count, 100)
XCTAssertEqual(waitingExporter.exporter.exportCalledTimes, 1)
Expand Down

0 comments on commit 31ba35e

Please sign in to comment.