forked from open-telemetry/opentelemetry-swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoggingSpan.swift
82 lines (65 loc) · 2.48 KB
/
LoggingSpan.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
import Foundation
import OpenTelemetryApi
class LoggingSpan: Span {
var name: String
var kind: SpanKind
var context: SpanContext
var isRecording: Bool = true
var status: Status = .unset
public init(name: String, kind: SpanKind) {
self.name = name
self.kind = kind
self.context = SpanContext.create(traceId: TraceId.random(),
spanId: SpanId.random(),
traceFlags: TraceFlags(),
traceState: TraceState())
}
public var description: String {
return name
}
public func updateName(name: String) {
Logger.log("Span.updateName(\(name))")
self.name = name
}
public func setAttribute(key: String, value: String) {
Logger.log("Span.setAttribute(key: \(key), value: \(value))")
}
public func setAttribute(key: String, value: Int) {
Logger.log("Span.setAttribute(key: \(key), value: \(value))")
}
public func setAttribute(key: String, value: Double) {
Logger.log("Span.setAttribute(key: \(key), value: \(value))")
}
public func setAttribute(key: String, value: Bool) {
Logger.log("Span.setAttribute(key: \(key), value: \(value))")
}
public func setAttribute(key: String, value: AttributeValue?) {
Logger.log("Span.setAttribute(key: \(key), value: \(String(describing: value)))")
}
public func setAttribute(keyValuePair: (String, AttributeValue)) {
Logger.log("Span.SetAttributes(keyValue: \(keyValuePair))")
setAttribute(key: keyValuePair.0, value: keyValuePair.1)
}
public func addEvent(name: String) {
Logger.log("Span.addEvent(\(name))")
}
public func addEvent(name: String, timestamp: Date) {
Logger.log("Span.addEvent(\(name) timestamp:\(timestamp))")
}
public func addEvent(name: String, attributes: [String: AttributeValue]) {
Logger.log("Span.addEvent(\(name), attributes:\(attributes) )")
}
public func addEvent(name: String, attributes: [String: AttributeValue], timestamp: Date) {
Logger.log("Span.addEvent(\(name), attributes:\(attributes), timestamp:\(timestamp))")
}
public func end() {
Logger.log("Span.End, Name: \(name)")
}
public func end(time: Date) {
Logger.log("Span.End, Name: \(name), time:\(time)) }")
}
}