diff --git a/README.md b/README.md index 7646352..5a26036 100644 --- a/README.md +++ b/README.md @@ -145,7 +145,7 @@ struct MyApp: App { Signoz.start(serviceName: "my-app") { config in config.endpoint = "localhost:4317" // default config.environment = "production" // deployment.environment - config.hostName = .auto // host.name (system hostname) + config.hostName = .auto // host.name (short system hostname, domain suffix stripped) config.hostName = .custom("web-01") // host.name (explicit value) // config.hostName = .none // omit host.name (default) config.serviceVersion = "1.0.0" @@ -274,7 +274,7 @@ let attrs: [String: AttributeValue] = [ | `serviceName` | `String` | *required* | Service name (`service.name`) | | `serviceVersion` | `String` | `""` | Service version (`service.version`) | | `environment` | `String` | `""` | Deployment environment (`deployment.environment`) | -| `hostName` | `.none` \| `.auto` \| `.custom(String)` | `.none` | Host name (`host.name`). `.none` omits the attribute, `.auto` uses the system hostname, `.custom("...")` uses an explicit value. | +| `hostName` | `.none` \| `.auto` \| `.custom(String)` | `.none` | Host name (`host.name`). `.none` omits the attribute, `.auto` uses the short system hostname (strips domain suffixes like `.local`), `.custom("...")` uses an explicit value. | | `resourceAttributes` | `[String: AttributeValue]` | `[:]` | Extra resource attributes | | `headers` | `[String: String]` | `[:]` | gRPC metadata headers | | `transportSecurity` | `.plaintext` \| `.tls` | `.plaintext` | Transport security mode | diff --git a/Sources/SignozSwift/Configuration.swift b/Sources/SignozSwift/Configuration.swift index 0aa13bd..d52881f 100644 --- a/Sources/SignozSwift/Configuration.swift +++ b/Sources/SignozSwift/Configuration.swift @@ -24,7 +24,7 @@ public struct Configuration: Sendable { /// Host name strategy for the `host.name` resource attribute. /// - `.none` — attribute is omitted (default). - /// - `.auto` — uses the system hostname at runtime. + /// - `.auto` — uses the short system hostname at runtime (strips domain suffixes like `.local`, `.localdomain`). /// - `.custom("value")` — uses the provided string. public var hostName: HostName = .none @@ -67,7 +67,7 @@ public struct Configuration: Sendable { public enum HostName: Sendable, Equatable, ExpressibleByStringLiteral { /// Do not include the `host.name` resource attribute. case none - /// Use the system hostname (`ProcessInfo.processInfo.hostName`). + /// Use the short system hostname (domain suffixes like `.local` stripped). case auto /// Use a custom hostname value. case custom(String) diff --git a/Sources/SignozSwift/Signoz.swift b/Sources/SignozSwift/Signoz.swift index b87578d..cffe1db 100644 --- a/Sources/SignozSwift/Signoz.swift +++ b/Sources/SignozSwift/Signoz.swift @@ -165,7 +165,9 @@ public enum Signoz { case .none: break case .auto: - attrs["host.name"] = .string(ProcessInfo.processInfo.hostName) + let raw = ProcessInfo.processInfo.hostName + let short = raw.split(separator: ".", maxSplits: 1).first.map(String.init) ?? raw + attrs["host.name"] = .string(short) case .custom(let value): attrs["host.name"] = .string(value) }