Skip to content

Commit eb35381

Browse files
author
Ignacio Bonafonte
authored
Merge branch 'main' into Save-spec-version-in-the-library
2 parents e6bba8a + da1b649 commit eb35381

File tree

4 files changed

+33
-17
lines changed

4 files changed

+33
-17
lines changed

README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,20 @@ or
3939
Official documentation for the library can be found in the official opentelemetry [documentation page](https://opentelemetry.io/docs/instrumentation/swift/), including:
4040

4141
* Documentation about installation and [manual instrumentation](https://opentelemetry.io/docs/instrumentation/swift/manual/)
42-
42+
4343
* [Libraries](https://opentelemetry.io/docs/instrumentation/swift/libraries/) that provide automatic instrumentation
4444

4545
## Current status
4646

4747
### API and SDK
4848

49-
Tracing and Baggage should be considered stable
49+
Tracing and Baggage are considered stable
5050

51-
Metrics is implemented using an outdated spec, is fully functional but will change in the future
51+
Logs are considered beta quality
5252

53-
Logs are currently in development
53+
Metrics is implemented using an outdated spec, is fully functional but will change in the future
5454

55-
### Supported exporters, importers and instrumentation libraries
55+
### Supported exporters and importers
5656

5757
#### Traces
5858
* Exporters: Stdout, Jaeger, Zipkin, Datadog and OpenTelemetry (OTLP) collector
@@ -62,7 +62,12 @@ Logs are currently in development
6262
* Exporters: Prometheus, Datadog, and OpenTelemetry (OTLP) collector
6363
* Importers: SwiftMetricsShim
6464

65-
#### Instrumentation libraries
65+
#### Logs
66+
* Exporters: OpenTelemetry (OTLP) collector
67+
68+
> **_NOTE:_** OTLP exporters are supported both in GRPC and HTTP/JSON, only GRPC is production ready, HTTP/JSON is still experimental
69+
70+
### Instrumentation libraries
6671
* URLSession
6772
* NetworkStatus
6873
* SDKResourceExtension
@@ -79,5 +84,3 @@ The package includes some example projects with basic functionality:
7984
- `Simple Exporter` - Shows the Jaeger an Stdout exporters in action using a MultiSpanExporter. Can be easily modified for other exporters
8085
- `Prometheus Sample` - Shows the Prometheus exporter reporting metrics to a Prometheus instance
8186
- `OTLP Exporter` - Shows the OTLP exporter reporting traces to Zipkin and metrics to a Prometheus via the otel-collector
82-
83-

Sources/OpenTelemetrySdk/Trace/AttributesDictionary.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public struct AttributesDictionary {
2929
}
3030
set {
3131
if newValue == nil {
32-
removeValueForKey(key: key)
32+
_ = removeValueForKey(key: key)
3333
} else {
3434
_ = updateValue(value: newValue!, forKey: key)
3535
}
@@ -81,11 +81,11 @@ public struct AttributesDictionary {
8181
}
8282
}
8383

84-
public mutating func removeValueForKey(key: String) {
84+
public mutating func removeValueForKey(key: String) -> AttributeValue? {
8585
keys = keys.filter {
8686
$0 != key
8787
}
88-
attributes.removeValue(forKey: key)
88+
return attributes.removeValue(forKey: key)
8989
}
9090

9191
public mutating func removeAll(keepCapacity: Int) {

Sources/OpenTelemetrySdk/Trace/RecordEventsReadableSpan.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,10 @@ public class RecordEventsReadableSpan: ReadableSpan {
242242
}
243243

244244
if value == nil {
245-
attributes.removeValueForKey(key: key)
245+
if attributes.removeValueForKey(key: key) != nil {
246+
totalAttributeCount -= 1
247+
}
248+
return
246249
}
247250
totalAttributeCount += 1
248251
if attributes[key] == nil, totalAttributeCount > maxNumberOfAttributes {

Tests/OpenTelemetrySdkTests/Trace/RecordEventsReadableSpanTests.swift

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,24 @@ class RecordEventsReadableSpanTest: XCTestCase {
235235
let spanData = span.toSpanData()
236236
XCTAssertEqual(spanData.events.count, 2)
237237
}
238-
238+
239239
func testWithInitializedAttributes() {
240-
241-
let attributes = ["hello" : AttributeValue.string("world")]
242-
240+
let attributes = ["hello": AttributeValue.string("world")]
241+
243242
let span = createTestSpan(attributes: attributes)
244-
243+
245244
XCTAssertEqual(attributes.count, span.totalAttributeCount, "total attributes not counted properly")
245+
XCTAssertEqual(span.toSpanData().attributes.count, span.totalAttributeCount, "total attributes not counted properly")
246+
247+
}
248+
249+
func testRemovingAttributes() {
250+
let attributes = ["remove": AttributeValue.string("me")]
251+
let span = createTestSpan(attributes: attributes)
252+
span.setAttribute(key: "keep", value: "me")
253+
span.setAttribute(key: "remove", value: nil)
254+
XCTAssertEqual(1, span.totalAttributeCount, "total attributes not counted properly")
255+
XCTAssertEqual(span.toSpanData().attributes.count, span.totalAttributeCount, "total attributes not counted properly")
246256
}
247257

248258
func testDroppingAttributes() {

0 commit comments

Comments
 (0)