Skip to content

Commit 7ed84cb

Browse files
Make some changes to allow creating spans directly without using SpanBuilder in the sdk. (#71)
RecordEventsReadableSpan.startSpan() was a public method, but could not be used because of some access control limitations, solve them: * AttributesWithCapacity methods are public now * TraceConfig settings are now readable
1 parent ca6be73 commit 7ed84cb

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

Sources/OpenTelemetrySdk/Trace/AttributesWithCapacity.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ public struct AttributesWithCapacity {
2424
private var capacity: Int
2525
private var recordedAttributes: Int
2626

27-
init(capacity: Int) {
27+
public init(capacity: Int) {
2828
attributes = [String: AttributeValue]()
2929
keys = [String]()
3030
recordedAttributes = 0
3131
self.capacity = capacity
3232
}
3333

34-
subscript(key: String) -> AttributeValue? {
34+
public subscript(key: String) -> AttributeValue? {
3535
get {
3636
attributes[key]
3737
}
@@ -44,7 +44,7 @@ public struct AttributesWithCapacity {
4444
}
4545
}
4646

47-
@discardableResult mutating func updateValue(value: AttributeValue, forKey key: String) -> AttributeValue? {
47+
@discardableResult public mutating func updateValue(value: AttributeValue, forKey key: String) -> AttributeValue? {
4848
let oldValue = attributes.updateValue(value, forKey: key)
4949
if oldValue == nil {
5050
recordedAttributes += 1
@@ -60,39 +60,39 @@ public struct AttributesWithCapacity {
6060
return oldValue
6161
}
6262

63-
mutating func updateValues(attributes: [String: AttributeValue]) {
63+
public mutating func updateValues(attributes: [String: AttributeValue]) {
6464
_ = attributes.keys.map {
6565
updateValue(value: attributes[$0]!, forKey: $0)
6666
}
6767
}
6868

69-
mutating func updateValues(attributes: AttributesWithCapacity) {
69+
public mutating func updateValues(attributes: AttributesWithCapacity) {
7070
_ = attributes.keys.map {
7171
updateValue(value: attributes[$0]!, forKey: $0)
7272
}
7373
}
7474

75-
mutating func removeValueForKey(key: String) {
75+
public mutating func removeValueForKey(key: String) {
7676
keys = keys.filter {
7777
$0 != key
7878
}
7979
attributes.removeValue(forKey: key)
8080
}
8181

82-
mutating func removeAll(keepCapacity: Int) {
82+
public mutating func removeAll(keepCapacity: Int) {
8383
keys = []
8484
attributes = Dictionary<String, AttributeValue>(minimumCapacity: keepCapacity)
8585
}
8686

87-
var count: Int {
87+
public var count: Int {
8888
attributes.count
8989
}
9090

91-
var numberOfDroppedAttributes: Int {
91+
public var numberOfDroppedAttributes: Int {
9292
recordedAttributes - attributes.count
9393
}
9494

95-
var values: Array<AttributeValue> {
95+
public var values: Array<AttributeValue> {
9696
keys.map { attributes[$0]! }
9797
}
9898

Sources/OpenTelemetrySdk/Trace/Config/TraceConfig.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,38 +22,38 @@ public struct TraceConfig: Equatable {
2222
// TODO: decide which default sampler to use
2323

2424
/// Returns the global default Sampler which is used when constructing a new Span
25-
var sampler: Sampler = Samplers.alwaysOn
25+
public private(set) var sampler: Sampler = Samplers.alwaysOn
2626

2727
/// The global default max number of attributes perSpan.
28-
var maxNumberOfAttributes: Int = 32 {
28+
public private(set) var maxNumberOfAttributes: Int = 32 {
2929
didSet {
3030
maxNumberOfAttributes < 0 ? maxNumberOfAttributes = 0 : Void()
3131
}
3232
}
3333

3434
/// the global default max number of Events per Span.
35-
var maxNumberOfEvents: Int = 128 {
35+
public private(set) var maxNumberOfEvents: Int = 128 {
3636
didSet {
3737
maxNumberOfEvents < 0 ? maxNumberOfEvents = 0 : Void()
3838
}
3939
}
4040

4141
/// the global default max number of Link entries per Span.
42-
var maxNumberOfLinks: Int = 32 {
42+
public private(set) var maxNumberOfLinks: Int = 32 {
4343
didSet {
4444
maxNumberOfLinks < 0 ? maxNumberOfLinks = 0 : Void()
4545
}
4646
}
4747

4848
/// the global default max number of attributes per Event.
49-
var maxNumberOfAttributesPerEvent: Int = 32 {
49+
public private(set) var maxNumberOfAttributesPerEvent: Int = 32 {
5050
didSet {
5151
maxNumberOfAttributesPerEvent < 0 ? maxNumberOfAttributesPerEvent = 0 : Void()
5252
}
5353
}
5454

5555
/// the global default max number of attributes per Link.
56-
var maxNumberOfAttributesPerLink: Int = 32 {
56+
public private(set) var maxNumberOfAttributesPerLink: Int = 32 {
5757
didSet {
5858
maxNumberOfAttributesPerLink < 0 ? maxNumberOfAttributesPerLink = 0 : Void()
5959
}

0 commit comments

Comments
 (0)