Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update the OTLP Exporter to match the changes in the metrics specifications (labels -> attributes) #300

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions Examples/OTLP Exporter/collector-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ receivers:
protocols:
grpc:
http:
cors_allowed_origins:
- http://*
- https://*
cors:
allowed_origins:
- http://*
- https://*

exporters:
logging:
loglevel: debug
zipkin:
endpoint: "http://zipkin-all-in-one:9411/api/v2/spans"
prometheus:
Expand All @@ -24,10 +23,13 @@ processors:
batch:

service:
telemetry:
logs:
level: "debug"
pipelines:
traces:
receivers: [otlp]
exporters: [zipkin, logging]
exporters: [zipkin]
processors: [resource, batch]
metrics:
receivers: [otlp]
Expand Down
4 changes: 2 additions & 2 deletions Examples/OTLP Exporter/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ version: "3"
services:
# Collector
collector:
image: otel/opentelemetry-collector:0.25.0
image: otel/opentelemetry-collector:0.50.0
# image: otel/opentelemetry-collector:latest
command: ["--config=/conf/collector-config.yaml", "--log-level=DEBUG"]
command: ["--config=/conf/collector-config.yaml"]
volumes:
- ./collector-config.yaml:/conf/collector-config.yaml
ports:
Expand Down
114 changes: 66 additions & 48 deletions Sources/Exporters/OpenTelemetryProtocol/metric/MetricsAdapter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,114 +54,132 @@ struct MetricsAdapter {
guard let gaugeData = $0 as? SumData<Double> else {
break
}
var protoDataPoint = Opentelemetry_Proto_Metrics_V1_DoubleDataPoint()
// var protoDataPoint = Opentelemetry_Proto_Metrics_V1_DoubleDataPoint()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed I think

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Trevor for catching it, I am cleaning up the commented sections of the code, as I was changing the MetricsAdapter.

var protoDataPoint = Opentelemetry_Proto_Metrics_V1_NumberDataPoint()

protoDataPoint.timeUnixNano = gaugeData.timestamp.timeIntervalSince1970.toNanoseconds
protoDataPoint.startTimeUnixNano = gaugeData.startTimestamp.timeIntervalSince1970.toNanoseconds
protoDataPoint.value = gaugeData.sum
protoDataPoint.value = .asDouble(gaugeData.sum)
gaugeData.labels.forEach {
var kvp = Opentelemetry_Proto_Common_V1_StringKeyValue()
// var kvp = Opentelemetry_Proto_Common_V1_StringKeyValue()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed I think

var kvp = Opentelemetry_Proto_Common_V1_KeyValue()
kvp.key = $0.key
kvp.value = $0.value
protoDataPoint.labels.append(kvp)
kvp.value.stringValue = $0.value
protoDataPoint.attributes.append(kvp)
}

protoMetric.doubleGauge.dataPoints.append(protoDataPoint)
protoMetric.gauge.dataPoints.append(protoDataPoint)
case .intGauge:
guard let gaugeData = $0 as? SumData<Int> else {
break
}

var protoDataPoint = Opentelemetry_Proto_Metrics_V1_IntDataPoint()
// var protoDataPoint = Opentelemetry_Proto_Metrics_V1_IntDataPoint()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed I think

var protoDataPoint = Opentelemetry_Proto_Metrics_V1_NumberDataPoint()

protoDataPoint.value = Int64(gaugeData.sum)
protoDataPoint.value = .asInt(Int64(exactly: gaugeData.sum)!)
protoDataPoint.timeUnixNano = gaugeData.timestamp.timeIntervalSince1970.toNanoseconds
protoDataPoint.startTimeUnixNano = gaugeData.startTimestamp.timeIntervalSince1970.toNanoseconds
gaugeData.labels.forEach {
var kvp = Opentelemetry_Proto_Common_V1_StringKeyValue()
// var kvp = Opentelemetry_Proto_Common_V1_StringKeyValue()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed I think

var kvp = Opentelemetry_Proto_Common_V1_KeyValue()
kvp.key = $0.key
kvp.value = $0.value
protoDataPoint.labels.append(kvp)
kvp.value.stringValue = $0.value
protoDataPoint.attributes.append(kvp)
}

protoMetric.intGauge.dataPoints.append(protoDataPoint)
protoMetric.gauge.dataPoints.append(protoDataPoint)
case .doubleSum:
guard let sumData = $0 as? SumData<Double> else {
break
}

var protoDataPoint = Opentelemetry_Proto_Metrics_V1_DoubleDataPoint()
protoDataPoint.value = sumData.sum
// var protoDataPoint = Opentelemetry_Proto_Metrics_V1_DoubleDataPoint()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed I think

var protoDataPoint = Opentelemetry_Proto_Metrics_V1_NumberDataPoint()

protoDataPoint.value = .asDouble(sumData.sum)
protoDataPoint.timeUnixNano = sumData.timestamp.timeIntervalSince1970.toNanoseconds
protoDataPoint.startTimeUnixNano = sumData.startTimestamp.timeIntervalSince1970.toNanoseconds
sumData.labels.forEach {
var kvp = Opentelemetry_Proto_Common_V1_StringKeyValue()
// var kvp = Opentelemetry_Proto_Common_V1_StringKeyValue()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed I think

var kvp = Opentelemetry_Proto_Common_V1_KeyValue()
kvp.key = $0.key
kvp.value = $0.value
protoDataPoint.labels.append(kvp)
kvp.value.stringValue = $0.value
protoDataPoint.attributes.append(kvp)
}

protoMetric.doubleSum.aggregationTemporality = .cumulative
protoMetric.doubleSum.dataPoints.append(protoDataPoint)
protoMetric.sum.aggregationTemporality = .cumulative
protoMetric.sum.dataPoints.append(protoDataPoint)
case .doubleSummary:

guard let summaryData = $0 as? SummaryData<Double> else {
break
}
var protoDataPoint = Opentelemetry_Proto_Metrics_V1_DoubleSummaryDataPoint()
// var protoDataPoint = Opentelemetry_Proto_Metrics_V1_DoubleSummaryDataPoint()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed I think

var protoDataPoint = Opentelemetry_Proto_Metrics_V1_SummaryDataPoint()

protoDataPoint.sum = summaryData.sum
protoDataPoint.count = UInt64(summaryData.count)

protoDataPoint.startTimeUnixNano = summaryData.startTimestamp.timeIntervalSince1970.toNanoseconds
protoDataPoint.timeUnixNano = summaryData.timestamp.timeIntervalSince1970.toNanoseconds

summaryData.labels.forEach {
var kvp = Opentelemetry_Proto_Common_V1_StringKeyValue()
var kvp = Opentelemetry_Proto_Common_V1_KeyValue()
kvp.key = $0.key
kvp.value = $0.value
protoDataPoint.labels.append(kvp)
kvp.value.stringValue = $0.value
protoDataPoint.attributes.append(kvp)
}

protoMetric.doubleSummary.dataPoints.append(protoDataPoint)
protoMetric.summary.dataPoints.append(protoDataPoint)
case .intSum:
guard let sumData = $0 as? SumData<Int> else {
break
}
var protoDataPoint = Opentelemetry_Proto_Metrics_V1_IntDataPoint()
protoDataPoint.value = Int64(sumData.sum)
// var protoDataPoint = Opentelemetry_Proto_Metrics_V1_IntDataPoint()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed I think

var protoDataPoint = Opentelemetry_Proto_Metrics_V1_NumberDataPoint()

protoDataPoint.value = .asInt(Int64(sumData.sum))
protoDataPoint.timeUnixNano = sumData.timestamp.timeIntervalSince1970.toNanoseconds
protoDataPoint.startTimeUnixNano = sumData.startTimestamp.timeIntervalSince1970.toNanoseconds
sumData.labels.forEach {
var kvp = Opentelemetry_Proto_Common_V1_StringKeyValue()
// var kvp = Opentelemetry_Proto_Common_V1_StringKeyValue()
var kvp = Opentelemetry_Proto_Common_V1_KeyValue()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed I think


kvp.key = $0.key
kvp.value = $0.value
protoDataPoint.labels.append(kvp)
kvp.value.stringValue = $0.value
protoDataPoint.attributes.append(kvp)
}

protoMetric.intSum.aggregationTemporality = .cumulative
protoMetric.intSum.dataPoints.append(protoDataPoint)
protoMetric.sum.aggregationTemporality = .cumulative
protoMetric.sum.dataPoints.append(protoDataPoint)
case .intSummary:
guard let summaryData = $0 as? SummaryData<Int> else {
break
}
var protoDataPoint = Opentelemetry_Proto_Metrics_V1_DoubleSummaryDataPoint()
// var protoDataPoint = Opentelemetry_Proto_Metrics_V1_DoubleSummaryDataPoint()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed I think

var protoDataPoint = Opentelemetry_Proto_Metrics_V1_SummaryDataPoint()

protoDataPoint.sum = Double(summaryData.sum)
protoDataPoint.count = UInt64(summaryData.count)
protoDataPoint.startTimeUnixNano = summaryData.startTimestamp.timeIntervalSince1970.toNanoseconds
protoDataPoint.timeUnixNano = summaryData.timestamp.timeIntervalSince1970.toNanoseconds

summaryData.labels.forEach {
var kvp = Opentelemetry_Proto_Common_V1_StringKeyValue()
var kvp = Opentelemetry_Proto_Common_V1_KeyValue()
kvp.key = $0.key
kvp.value = $0.value
protoDataPoint.labels.append(kvp)
kvp.value.stringValue = $0.value
protoDataPoint.attributes.append(kvp)
}

protoMetric.doubleSummary.dataPoints.append(protoDataPoint)
protoMetric.summary.dataPoints.append(protoDataPoint)
case .intHistogram:
guard let histogramData = $0 as? HistogramData<Int> else {
break
}
var protoDataPoint = Opentelemetry_Proto_Metrics_V1_DoubleHistogramDataPoint()
// var protoDataPoint = Opentelemetry_Proto_Metrics_V1_DoubleHistogramDataPoint()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed I think

var protoDataPoint = Opentelemetry_Proto_Metrics_V1_HistogramDataPoint()

protoDataPoint.sum = Double(histogramData.sum)
protoDataPoint.count = UInt64(histogramData.count)
protoDataPoint.startTimeUnixNano = histogramData.startTimestamp.timeIntervalSince1970.toNanoseconds
Expand All @@ -170,19 +188,19 @@ struct MetricsAdapter {
protoDataPoint.bucketCounts = histogramData.buckets.counts.map { UInt64($0) }

histogramData.labels.forEach {
var kvp = Opentelemetry_Proto_Common_V1_StringKeyValue()
var kvp = Opentelemetry_Proto_Common_V1_KeyValue()
kvp.key = $0.key
kvp.value = $0.value
protoDataPoint.labels.append(kvp)
kvp.value.stringValue = $0.value
protoDataPoint.attributes.append(kvp)
}

protoMetric.doubleHistogram.aggregationTemporality = .cumulative
protoMetric.doubleHistogram.dataPoints.append(protoDataPoint)
protoMetric.histogram.aggregationTemporality = .cumulative
protoMetric.histogram.dataPoints.append(protoDataPoint)
case .doubleHistogram:
guard let histogramData = $0 as? HistogramData<Double> else {
break
}
var protoDataPoint = Opentelemetry_Proto_Metrics_V1_DoubleHistogramDataPoint()
var protoDataPoint = Opentelemetry_Proto_Metrics_V1_HistogramDataPoint()
protoDataPoint.sum = Double(histogramData.sum)
protoDataPoint.count = UInt64(histogramData.count)
protoDataPoint.startTimeUnixNano = histogramData.startTimestamp.timeIntervalSince1970.toNanoseconds
Expand All @@ -191,14 +209,14 @@ struct MetricsAdapter {
protoDataPoint.bucketCounts = histogramData.buckets.counts.map { UInt64($0) }

histogramData.labels.forEach {
var kvp = Opentelemetry_Proto_Common_V1_StringKeyValue()
var kvp = Opentelemetry_Proto_Common_V1_KeyValue()
kvp.key = $0.key
kvp.value = $0.value
protoDataPoint.labels.append(kvp)
kvp.value.stringValue = $0.value
protoDataPoint.attributes.append(kvp)
}

protoMetric.doubleHistogram.aggregationTemporality = .cumulative
protoMetric.doubleHistogram.dataPoints.append(protoDataPoint)
protoMetric.histogram.aggregationTemporality = .cumulative
protoMetric.histogram.dataPoints.append(protoDataPoint)
}
}
return protoMetric
Expand Down
Loading