Skip to content

Commit 7948b1c

Browse files
committed
Merge branch 'main' into fixes-sysctl-issue-on-mac
2 parents 5d494fe + fe831f0 commit 7948b1c

File tree

15 files changed

+1781
-1180
lines changed

15 files changed

+1781
-1180
lines changed

Examples/OTLP Exporter/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ The prometheus client will be available at <http://localhost:9090>.
3838
Note: It may take some time for the application metrics to appear on the Prometheus dashboard.
3939
![Screenshot of the running example](images/prometheus-metrics.png)
4040

41+
5. If you don't set service.name as per https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/sdk-environment-variables.md the default name of the service and spans generate by the OTLP Exporter is `unknown_service:otlpexporter` You can either set the service.name by editing the schema in Xcode and the set the environment variable for OTEL_RESOURCE_ATTRIBUTES, or set it via command line:
42+
43+
```shell script
44+
# from this directory
45+
OTEL_RESOURCE_ATTRIBUTES="service.name=my-swift-app,service.version=v1.2.3" swift run OTLPExporter
46+
```
47+
This will create a service and spans with the name `my-swift-app`
48+
4149
## Useful links
4250
4351
- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>

Examples/OTLP Exporter/collector-config.yaml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ receivers:
33
protocols:
44
grpc:
55
http:
6-
cors_allowed_origins:
7-
- http://*
8-
- https://*
6+
cors:
7+
allowed_origins:
8+
- http://*
9+
- https://*
910

1011
exporters:
11-
logging:
12-
loglevel: debug
1312
zipkin:
1413
endpoint: "http://zipkin-all-in-one:9411/api/v2/spans"
1514
prometheus:
@@ -24,10 +23,13 @@ processors:
2423
batch:
2524

2625
service:
26+
telemetry:
27+
logs:
28+
level: "debug"
2729
pipelines:
2830
traces:
2931
receivers: [otlp]
30-
exporters: [zipkin, logging]
32+
exporters: [zipkin]
3133
processors: [resource, batch]
3234
metrics:
3335
receivers: [otlp]

Examples/OTLP Exporter/docker-compose.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ version: "3"
22
services:
33
# Collector
44
collector:
5-
image: otel/opentelemetry-collector:0.25.0
5+
image: otel/opentelemetry-collector:0.50.0
66
# image: otel/opentelemetry-collector:latest
7-
command: ["--config=/conf/collector-config.yaml", "--log-level=DEBUG"]
7+
command: ["--config=/conf/collector-config.yaml"]
88
volumes:
99
- ./collector-config.yaml:/conf/collector-config.yaml
1010
ports:

Sources/Exporters/OpenTelemetryProtocol/metric/MetricsAdapter.swift

Lines changed: 55 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -54,114 +54,121 @@ struct MetricsAdapter {
5454
guard let gaugeData = $0 as? SumData<Double> else {
5555
break
5656
}
57-
var protoDataPoint = Opentelemetry_Proto_Metrics_V1_DoubleDataPoint()
57+
var protoDataPoint = Opentelemetry_Proto_Metrics_V1_NumberDataPoint()
58+
5859
protoDataPoint.timeUnixNano = gaugeData.timestamp.timeIntervalSince1970.toNanoseconds
5960
protoDataPoint.startTimeUnixNano = gaugeData.startTimestamp.timeIntervalSince1970.toNanoseconds
60-
protoDataPoint.value = gaugeData.sum
61+
protoDataPoint.value = .asDouble(gaugeData.sum)
6162
gaugeData.labels.forEach {
62-
var kvp = Opentelemetry_Proto_Common_V1_StringKeyValue()
63+
var kvp = Opentelemetry_Proto_Common_V1_KeyValue()
6364
kvp.key = $0.key
64-
kvp.value = $0.value
65-
protoDataPoint.labels.append(kvp)
65+
kvp.value.stringValue = $0.value
66+
protoDataPoint.attributes.append(kvp)
6667
}
6768

68-
protoMetric.doubleGauge.dataPoints.append(protoDataPoint)
69+
protoMetric.gauge.dataPoints.append(protoDataPoint)
6970
case .intGauge:
7071
guard let gaugeData = $0 as? SumData<Int> else {
7172
break
7273
}
7374

74-
var protoDataPoint = Opentelemetry_Proto_Metrics_V1_IntDataPoint()
75+
var protoDataPoint = Opentelemetry_Proto_Metrics_V1_NumberDataPoint()
7576

76-
protoDataPoint.value = Int64(gaugeData.sum)
77+
protoDataPoint.value = .asInt(Int64(exactly: gaugeData.sum)!)
7778
protoDataPoint.timeUnixNano = gaugeData.timestamp.timeIntervalSince1970.toNanoseconds
7879
protoDataPoint.startTimeUnixNano = gaugeData.startTimestamp.timeIntervalSince1970.toNanoseconds
7980
gaugeData.labels.forEach {
80-
var kvp = Opentelemetry_Proto_Common_V1_StringKeyValue()
81+
var kvp = Opentelemetry_Proto_Common_V1_KeyValue()
8182
kvp.key = $0.key
82-
kvp.value = $0.value
83-
protoDataPoint.labels.append(kvp)
83+
kvp.value.stringValue = $0.value
84+
protoDataPoint.attributes.append(kvp)
8485
}
8586

86-
protoMetric.intGauge.dataPoints.append(protoDataPoint)
87+
protoMetric.gauge.dataPoints.append(protoDataPoint)
8788
case .doubleSum:
8889
guard let sumData = $0 as? SumData<Double> else {
8990
break
9091
}
9192

92-
var protoDataPoint = Opentelemetry_Proto_Metrics_V1_DoubleDataPoint()
93-
protoDataPoint.value = sumData.sum
93+
var protoDataPoint = Opentelemetry_Proto_Metrics_V1_NumberDataPoint()
94+
95+
protoDataPoint.value = .asDouble(sumData.sum)
9496
protoDataPoint.timeUnixNano = sumData.timestamp.timeIntervalSince1970.toNanoseconds
9597
protoDataPoint.startTimeUnixNano = sumData.startTimestamp.timeIntervalSince1970.toNanoseconds
9698
sumData.labels.forEach {
97-
var kvp = Opentelemetry_Proto_Common_V1_StringKeyValue()
99+
var kvp = Opentelemetry_Proto_Common_V1_KeyValue()
98100
kvp.key = $0.key
99-
kvp.value = $0.value
100-
protoDataPoint.labels.append(kvp)
101+
kvp.value.stringValue = $0.value
102+
protoDataPoint.attributes.append(kvp)
101103
}
102104

103-
protoMetric.doubleSum.aggregationTemporality = .cumulative
104-
protoMetric.doubleSum.dataPoints.append(protoDataPoint)
105+
protoMetric.sum.aggregationTemporality = .cumulative
106+
protoMetric.sum.dataPoints.append(protoDataPoint)
105107
case .doubleSummary:
106108

107109
guard let summaryData = $0 as? SummaryData<Double> else {
108110
break
109111
}
110-
var protoDataPoint = Opentelemetry_Proto_Metrics_V1_DoubleSummaryDataPoint()
112+
var protoDataPoint = Opentelemetry_Proto_Metrics_V1_SummaryDataPoint()
113+
111114
protoDataPoint.sum = summaryData.sum
112115
protoDataPoint.count = UInt64(summaryData.count)
113116

114117
protoDataPoint.startTimeUnixNano = summaryData.startTimestamp.timeIntervalSince1970.toNanoseconds
115118
protoDataPoint.timeUnixNano = summaryData.timestamp.timeIntervalSince1970.toNanoseconds
116119

117120
summaryData.labels.forEach {
118-
var kvp = Opentelemetry_Proto_Common_V1_StringKeyValue()
121+
var kvp = Opentelemetry_Proto_Common_V1_KeyValue()
119122
kvp.key = $0.key
120-
kvp.value = $0.value
121-
protoDataPoint.labels.append(kvp)
123+
kvp.value.stringValue = $0.value
124+
protoDataPoint.attributes.append(kvp)
122125
}
123126

124-
protoMetric.doubleSummary.dataPoints.append(protoDataPoint)
127+
protoMetric.summary.dataPoints.append(protoDataPoint)
125128
case .intSum:
126129
guard let sumData = $0 as? SumData<Int> else {
127130
break
128131
}
129-
var protoDataPoint = Opentelemetry_Proto_Metrics_V1_IntDataPoint()
130-
protoDataPoint.value = Int64(sumData.sum)
132+
var protoDataPoint = Opentelemetry_Proto_Metrics_V1_NumberDataPoint()
133+
134+
protoDataPoint.value = .asInt(Int64(sumData.sum))
131135
protoDataPoint.timeUnixNano = sumData.timestamp.timeIntervalSince1970.toNanoseconds
132136
protoDataPoint.startTimeUnixNano = sumData.startTimestamp.timeIntervalSince1970.toNanoseconds
133137
sumData.labels.forEach {
134-
var kvp = Opentelemetry_Proto_Common_V1_StringKeyValue()
138+
var kvp = Opentelemetry_Proto_Common_V1_KeyValue()
139+
135140
kvp.key = $0.key
136-
kvp.value = $0.value
137-
protoDataPoint.labels.append(kvp)
141+
kvp.value.stringValue = $0.value
142+
protoDataPoint.attributes.append(kvp)
138143
}
139144

140-
protoMetric.intSum.aggregationTemporality = .cumulative
141-
protoMetric.intSum.dataPoints.append(protoDataPoint)
145+
protoMetric.sum.aggregationTemporality = .cumulative
146+
protoMetric.sum.dataPoints.append(protoDataPoint)
142147
case .intSummary:
143148
guard let summaryData = $0 as? SummaryData<Int> else {
144149
break
145150
}
146-
var protoDataPoint = Opentelemetry_Proto_Metrics_V1_DoubleSummaryDataPoint()
151+
var protoDataPoint = Opentelemetry_Proto_Metrics_V1_SummaryDataPoint()
152+
147153
protoDataPoint.sum = Double(summaryData.sum)
148154
protoDataPoint.count = UInt64(summaryData.count)
149155
protoDataPoint.startTimeUnixNano = summaryData.startTimestamp.timeIntervalSince1970.toNanoseconds
150156
protoDataPoint.timeUnixNano = summaryData.timestamp.timeIntervalSince1970.toNanoseconds
151157

152158
summaryData.labels.forEach {
153-
var kvp = Opentelemetry_Proto_Common_V1_StringKeyValue()
159+
var kvp = Opentelemetry_Proto_Common_V1_KeyValue()
154160
kvp.key = $0.key
155-
kvp.value = $0.value
156-
protoDataPoint.labels.append(kvp)
161+
kvp.value.stringValue = $0.value
162+
protoDataPoint.attributes.append(kvp)
157163
}
158164

159-
protoMetric.doubleSummary.dataPoints.append(protoDataPoint)
165+
protoMetric.summary.dataPoints.append(protoDataPoint)
160166
case .intHistogram:
161167
guard let histogramData = $0 as? HistogramData<Int> else {
162168
break
163169
}
164-
var protoDataPoint = Opentelemetry_Proto_Metrics_V1_DoubleHistogramDataPoint()
170+
var protoDataPoint = Opentelemetry_Proto_Metrics_V1_HistogramDataPoint()
171+
165172
protoDataPoint.sum = Double(histogramData.sum)
166173
protoDataPoint.count = UInt64(histogramData.count)
167174
protoDataPoint.startTimeUnixNano = histogramData.startTimestamp.timeIntervalSince1970.toNanoseconds
@@ -170,19 +177,19 @@ struct MetricsAdapter {
170177
protoDataPoint.bucketCounts = histogramData.buckets.counts.map { UInt64($0) }
171178

172179
histogramData.labels.forEach {
173-
var kvp = Opentelemetry_Proto_Common_V1_StringKeyValue()
180+
var kvp = Opentelemetry_Proto_Common_V1_KeyValue()
174181
kvp.key = $0.key
175-
kvp.value = $0.value
176-
protoDataPoint.labels.append(kvp)
182+
kvp.value.stringValue = $0.value
183+
protoDataPoint.attributes.append(kvp)
177184
}
178185

179-
protoMetric.doubleHistogram.aggregationTemporality = .cumulative
180-
protoMetric.doubleHistogram.dataPoints.append(protoDataPoint)
186+
protoMetric.histogram.aggregationTemporality = .cumulative
187+
protoMetric.histogram.dataPoints.append(protoDataPoint)
181188
case .doubleHistogram:
182189
guard let histogramData = $0 as? HistogramData<Double> else {
183190
break
184191
}
185-
var protoDataPoint = Opentelemetry_Proto_Metrics_V1_DoubleHistogramDataPoint()
192+
var protoDataPoint = Opentelemetry_Proto_Metrics_V1_HistogramDataPoint()
186193
protoDataPoint.sum = Double(histogramData.sum)
187194
protoDataPoint.count = UInt64(histogramData.count)
188195
protoDataPoint.startTimeUnixNano = histogramData.startTimestamp.timeIntervalSince1970.toNanoseconds
@@ -191,14 +198,14 @@ struct MetricsAdapter {
191198
protoDataPoint.bucketCounts = histogramData.buckets.counts.map { UInt64($0) }
192199

193200
histogramData.labels.forEach {
194-
var kvp = Opentelemetry_Proto_Common_V1_StringKeyValue()
201+
var kvp = Opentelemetry_Proto_Common_V1_KeyValue()
195202
kvp.key = $0.key
196-
kvp.value = $0.value
197-
protoDataPoint.labels.append(kvp)
203+
kvp.value.stringValue = $0.value
204+
protoDataPoint.attributes.append(kvp)
198205
}
199206

200-
protoMetric.doubleHistogram.aggregationTemporality = .cumulative
201-
protoMetric.doubleHistogram.dataPoints.append(protoDataPoint)
207+
protoMetric.histogram.aggregationTemporality = .cumulative
208+
protoMetric.histogram.dataPoints.append(protoDataPoint)
202209
}
203210
}
204211
return protoMetric

0 commit comments

Comments
 (0)