Skip to content

Commit 8ce63e4

Browse files
author
Michal A
committed
Make SpanAttribute ExpressibleByStringInterpolation
1 parent 284912e commit 8ce63e4

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

Sources/Instrumentation/Tracing/Span.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ extension SpanAttribute: ExpressibleByStringLiteral {
137137
}
138138
}
139139

140+
extension SpanAttribute: ExpressibleByStringInterpolation {
141+
public init(stringInterpolation value: Self.StringInterpolation) {
142+
self = .string("\(value)")
143+
}
144+
}
145+
140146
extension SpanAttribute: ExpressibleByIntegerLiteral {
141147
public init(integerLiteral value: Int) {
142148
self = .int(value)

Tests/InstrumentationTests/SpanTests.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ final class SpanTests: XCTestCase {
4848
XCTAssertEqual(stringValue, "test")
4949
}
5050

51+
func testSpanAttributeIsExpressibleByStringInterpolation() {
52+
let stringAttribute: SpanAttribute = "test \(true) \(42) \(3.14)"
53+
guard case .string(let stringValue) = stringAttribute else {
54+
XCTFail("Expected string attribute, got \(stringAttribute).")
55+
return
56+
}
57+
XCTAssertEqual(stringValue, "test true 42 3.14")
58+
}
59+
5160
func testSpanAttributeIsExpressibleByIntegerLiteral() {
5261
let intAttribute: SpanAttribute = 42
5362
guard case .int(let intValue) = intAttribute else {

0 commit comments

Comments
 (0)