Skip to content

Commit 325829c

Browse files
committed
deprecate SessionConstants.id and prevId
1 parent 2ec6fb5 commit 325829c

File tree

5 files changed

+29
-27
lines changed

5 files changed

+29
-27
lines changed

Sources/Instrumentation/Sessions/SessionConstants.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ public class SessionConstants {
2020
/// Event name for session end events
2121
public static let sessionEndEvent = "session.end"
2222
/// Attribute name for session identifier
23+
@available(*, deprecated, message: "Use SemanticConventions.Session.id instead")
2324
public static let id = "session.id"
2425
/// Attribute name for previous session identifier
26+
@available(*, deprecated, message: "Use SemanticConventions.Session.previousId instead")
2527
public static let previousId = "session.previous_id"
2628

2729
// MARK: - Extension Attributes
@@ -35,4 +37,4 @@ public class SessionConstants {
3537
public static let sessionEventNotification = "SessionEventInstrumentation.SessionEvent"
3638
}
3739

38-
let SessionEventNotification = Notification.Name(SessionConstants.sessionEventNotification)
40+
let SessionEventNotification = Notification.Name(SessionConstants.sessionEventNotification)

Sources/Instrumentation/Sessions/SessionEventInstrumentation.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ public class SessionEventInstrumentation {
108108
/// - Parameter session: The session that has started
109109
private static func createSessionStartEvent(session: Session) {
110110
var attributes: [String: AttributeValue] = [
111-
SessionConstants.id: AttributeValue.string(session.id)
111+
SemanticConventions.Session.id.rawValue: AttributeValue.string(session.id)
112112
]
113113

114114
if let previousId = session.previousId {
115-
attributes[SessionConstants.previousId] = AttributeValue.string(previousId)
115+
attributes[SemanticConventions.Session.previousId.rawValue] = AttributeValue.string(previousId)
116116
}
117117

118118
/// Create `session.start` log record according to otel semantic convention
@@ -136,12 +136,12 @@ public class SessionEventInstrumentation {
136136
}
137137

138138
var attributes: [String: AttributeValue] = [
139-
SessionConstants.id: AttributeValue.string(session.id),
139+
SemanticConventions.Session.id.rawValue: AttributeValue.string(session.id),
140140
SessionConstants.duration: AttributeValue.double(Double(duration.toNanoseconds))
141141
]
142142

143143
if let previousId = session.previousId {
144-
attributes[SessionConstants.previousId] = AttributeValue.string(previousId)
144+
attributes[SemanticConventions.Session.previousId.rawValue] = AttributeValue.string(previousId)
145145
}
146146

147147
/// Create `session.end`` log record according to otel semantic convention

Sources/Instrumentation/Sessions/SessionLogRecordProcessor.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ public class SessionLogRecordProcessor: LogRecordProcessor {
2525
var enhancedRecord = logRecord
2626

2727
// Only add session attributes if they don't already exist
28-
if logRecord.attributes[SessionConstants.id] == nil || logRecord.attributes[SessionConstants.previousId] == nil {
28+
if logRecord.attributes[SemanticConventions.Session.id.rawValue] == nil || logRecord.attributes[SemanticConventions.Session.previousId.rawValue] == nil {
2929
let session = sessionManager.getSession()
3030

3131
// Add session.id if not already present
32-
if logRecord.attributes[SessionConstants.id] == nil {
33-
enhancedRecord.setAttribute(key: SessionConstants.id, value: session.id)
32+
if logRecord.attributes[SemanticConventions.Session.id.rawValue] == nil {
33+
enhancedRecord.setAttribute(key: SemanticConventions.Session.id.rawValue, value: session.id)
3434
}
3535

3636
// Add session.previous_id if not already present and session has a previous ID
37-
if logRecord.attributes[SessionConstants.previousId] == nil, let previousId = session.previousId {
38-
enhancedRecord.setAttribute(key: SessionConstants.previousId, value: previousId)
37+
if logRecord.attributes[SemanticConventions.Session.previousId.rawValue] == nil, let previousId = session.previousId {
38+
enhancedRecord.setAttribute(key: SemanticConventions.Session.previousId.rawValue, value: previousId)
3939
}
4040
}
4141

Sources/Instrumentation/Sessions/SessionSpanProcessor.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ public class SessionSpanProcessor: SpanProcessor {
2929
/// - span: The span being started
3030
public func onStart(parentContext: SpanContext?, span: ReadableSpan) {
3131
let session = sessionManager.getSession()
32-
span.setAttribute(key: SessionConstants.id, value: session.id)
32+
span.setAttribute(key: SemanticConventions.Session.id.rawValue, value: session.id)
3333
if session.previousId != nil {
34-
span.setAttribute(key: SessionConstants.previousId, value: session.previousId!)
34+
span.setAttribute(key: SemanticConventions.Session.previousId.rawValue, value: session.previousId!)
3535
}
3636
}
3737

Tests/InstrumentationTests/SessionTests/SessionLogRecordProcessorTests.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ final class SessionLogRecordProcessorTests: XCTestCase {
3636
XCTAssertEqual(mockNextProcessor.receivedLogRecords.count, 1)
3737
let enhancedRecord = mockNextProcessor.receivedLogRecords[0]
3838

39-
if case let .string(sessionId) = enhancedRecord.attributes[SessionConstants.id] {
39+
if case let .string(sessionId) = enhancedRecord.attributes[SemanticConventions.Session.id.rawValue] {
4040
XCTAssertEqual(sessionId, expectedSessionId)
4141
} else {
4242
XCTFail("Expected session.id attribute to be a string value")
@@ -75,13 +75,13 @@ final class SessionLogRecordProcessorTests: XCTestCase {
7575

7676
let enhancedRecord = mockNextProcessor.receivedLogRecords[0]
7777

78-
if case let .string(sessionId) = enhancedRecord.attributes[SessionConstants.id] {
78+
if case let .string(sessionId) = enhancedRecord.attributes[SemanticConventions.Session.id.rawValue] {
7979
XCTAssertEqual(sessionId, expectedSessionId)
8080
} else {
8181
XCTFail("Expected session.id attribute to be a string value")
8282
}
8383

84-
if case let .string(previousSessionId) = enhancedRecord.attributes[SessionConstants.previousId] {
84+
if case let .string(previousSessionId) = enhancedRecord.attributes[SemanticConventions.Session.previousId.rawValue] {
8585
XCTAssertEqual(previousSessionId, expectedPreviousSessionId)
8686
} else {
8787
XCTFail("Expected session.previous_id attribute to be a string value")
@@ -97,13 +97,13 @@ final class SessionLogRecordProcessorTests: XCTestCase {
9797

9898
let enhancedRecord = mockNextProcessor.receivedLogRecords[0]
9999

100-
if case let .string(sessionId) = enhancedRecord.attributes[SessionConstants.id] {
100+
if case let .string(sessionId) = enhancedRecord.attributes[SemanticConventions.Session.id.rawValue] {
101101
XCTAssertEqual(sessionId, expectedSessionId)
102102
} else {
103103
XCTFail("Expected session.id attribute to be a string value")
104104
}
105105

106-
XCTAssertNil(enhancedRecord.attributes[SessionConstants.previousId], "Previous session ID should not be set when nil")
106+
XCTAssertNil(enhancedRecord.attributes[SemanticConventions.Session.previousId.rawValue], "Previous session ID should not be set when nil")
107107
}
108108

109109
func testOnEmitWithDifferentSessionIds() {
@@ -115,13 +115,13 @@ final class SessionLogRecordProcessorTests: XCTestCase {
115115

116116
XCTAssertEqual(mockNextProcessor.receivedLogRecords.count, 2)
117117

118-
if case let .string(sessionId1) = mockNextProcessor.receivedLogRecords[0].attributes[SessionConstants.id] {
118+
if case let .string(sessionId1) = mockNextProcessor.receivedLogRecords[0].attributes[SemanticConventions.Session.id.rawValue] {
119119
XCTAssertEqual(sessionId1, "session-1")
120120
} else {
121121
XCTFail("Expected first log record to have session-1")
122122
}
123123

124-
if case let .string(sessionId2) = mockNextProcessor.receivedLogRecords[1].attributes[SessionConstants.id] {
124+
if case let .string(sessionId2) = mockNextProcessor.receivedLogRecords[1].attributes[SemanticConventions.Session.id.rawValue] {
125125
XCTAssertEqual(sessionId2, "session-2")
126126
} else {
127127
XCTFail("Expected second log record to have session-2")
@@ -148,8 +148,8 @@ final class SessionLogRecordProcessorTests: XCTestCase {
148148
severity: .info,
149149
body: AttributeValue.string("session.start"),
150150
attributes: [
151-
SessionConstants.id: AttributeValue.string("existing-session-123"),
152-
SessionConstants.previousId: AttributeValue.string("existing-previous-456")
151+
SemanticConventions.Session.id.rawValue: AttributeValue.string("existing-session-123"),
152+
SemanticConventions.Session.previousId.rawValue: AttributeValue.string("existing-previous-456")
153153
]
154154
)
155155

@@ -158,13 +158,13 @@ final class SessionLogRecordProcessorTests: XCTestCase {
158158

159159
let enhancedRecord = mockNextProcessor.receivedLogRecords[0]
160160

161-
if case let .string(sessionId) = enhancedRecord.attributes[SessionConstants.id] {
161+
if case let .string(sessionId) = enhancedRecord.attributes[SemanticConventions.Session.id.rawValue] {
162162
XCTAssertEqual(sessionId, "existing-session-123", "Should preserve existing session ID for session.start")
163163
} else {
164164
XCTFail("Expected existing session.id to be preserved")
165165
}
166166

167-
if case let .string(previousId) = enhancedRecord.attributes[SessionConstants.previousId] {
167+
if case let .string(previousId) = enhancedRecord.attributes[SemanticConventions.Session.previousId.rawValue] {
168168
XCTAssertEqual(previousId, "existing-previous-456", "Should preserve existing previous session ID")
169169
} else {
170170
XCTFail("Expected existing session.previous_id to be preserved")
@@ -181,7 +181,7 @@ final class SessionLogRecordProcessorTests: XCTestCase {
181181
severity: .info,
182182
body: AttributeValue.string("session.end"),
183183
attributes: [
184-
SessionConstants.id: AttributeValue.string("ending-session-789"),
184+
SemanticConventions.Session.id.rawValue: AttributeValue.string("ending-session-789"),
185185
"session.duration": AttributeValue.double(123.45)
186186
]
187187
)
@@ -191,7 +191,7 @@ final class SessionLogRecordProcessorTests: XCTestCase {
191191

192192
let enhancedRecord = mockNextProcessor.receivedLogRecords[0]
193193

194-
if case let .string(sessionId) = enhancedRecord.attributes[SessionConstants.id] {
194+
if case let .string(sessionId) = enhancedRecord.attributes[SemanticConventions.Session.id.rawValue] {
195195
XCTAssertEqual(sessionId, "ending-session-789", "Should preserve existing session ID for session.end")
196196
} else {
197197
XCTFail("Expected existing session.id to be preserved")
@@ -234,7 +234,7 @@ final class SessionLogRecordProcessorTests: XCTestCase {
234234
XCTAssertEqual(enhancedRecord.spanContext, logRecordWithEventName.spanContext)
235235

236236
// Verify session attributes were added
237-
if case let .string(sessionId) = enhancedRecord.attributes[SessionConstants.id] {
237+
if case let .string(sessionId) = enhancedRecord.attributes[SemanticConventions.Session.id.rawValue] {
238238
XCTAssertEqual(sessionId, "test-session-123")
239239
} else {
240240
XCTFail("Expected session.id attribute to be added")
@@ -276,7 +276,7 @@ final class SessionLogRecordProcessorTests: XCTestCase {
276276

277277
XCTAssertEqual(mockNextProcessor.receivedLogRecords.count, 10)
278278
for record in mockNextProcessor.receivedLogRecords {
279-
XCTAssertTrue(record.attributes.keys.contains(SessionConstants.id))
279+
XCTAssertTrue(record.attributes.keys.contains(SemanticConventions.Session.id.rawValue))
280280
}
281281
}
282282
}

0 commit comments

Comments
 (0)