Skip to content

Commit

Permalink
Changes based on PR comments
Browse files Browse the repository at this point in the history
Naming, swift-otel version, log level
  • Loading branch information
adam-fowler committed Dec 29, 2024
1 parent 5768e93 commit 5f8e7ed
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
2 changes: 1 addition & 1 deletion open-telemetry/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let package = Package(
dependencies: [
.package(url: "https://github.com/hummingbird-project/hummingbird.git", from: "2.0.0"),
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.3.0"),
.package(url: "https://github.com/swift-otel/swift-otel.git", from: "0.10.0"),
.package(url: "https://github.com/swift-otel/swift-otel.git", .upToNextMinor(from: "0.10.0")),
],
targets: [
.executableTarget(
Expand Down
2 changes: 1 addition & 1 deletion open-telemetry/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Open Telemetry

Integrate with Open Telemetry using [swift-otel](https://github.com/swift-otel/swift-otel).
Integrate with OpenTelemetry using [swift-otel](https://github.com/swift-otel/swift-otel).
16 changes: 6 additions & 10 deletions open-telemetry/Sources/App/Application+build.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,18 @@ typealias AppRequestContext = BasicRequestContext
/// Build application
/// - Parameter arguments: application arguments
public func buildApplication(_ arguments: some AppArguments) async throws -> some ApplicationProtocol {
let environment = Environment()
// Bootstrap the logging backend with the OTel metadata provider which includes span IDs in logging messages.
let logLevel = arguments.logLevel ?? environment.get("LOG_LEVEL").flatMap { Logger.Level(rawValue: $0) } ?? .debug
LoggingSystem.bootstrap { label in
var handler = StreamLogHandler.standardError(label: label, metadataProvider: .otel)
handler.logLevel = .trace
handler.logLevel = logLevel
return handler
}

let environment = Environment()
let logger = {
var logger = Logger(label: "open-telemetry")
logger.logLevel =
arguments.logLevel ?? environment.get("LOG_LEVEL").flatMap { Logger.Level(rawValue: $0) } ?? .info
return logger
}()
let logger = Logger(label: "open-telemetry")

let otel = try await setupOTEL()
let otel = try await setupOTel()

let router = buildRouter()
var app = Application(
Expand All @@ -52,7 +48,7 @@ public func buildApplication(_ arguments: some AppArguments) async throws -> som
return app
}

func setupOTEL() async throws -> (metrics: Service, tracer: Service) {
func setupOTel() async throws -> (metrics: Service, tracer: Service) {
// Configure OTel resource detection to automatically apply helpful attributes to events.
let environment = OTelEnvironment.detected()
let resourceDetection = OTelResourceDetection(detectors: [
Expand Down

0 comments on commit 5f8e7ed

Please sign in to comment.