-
Notifications
You must be signed in to change notification settings - Fork 559
[Metrics] Add OTLP http metric exporter #1487
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
61b240f
Add OTLP http metric exporter
owent 19df9cc
Add changelog for OTLP HTTP metric exporter
owent bb61deb
Add unit test of `SumPointData` for `OtlpHttpMetricExporter`
owent 1001577
Fix dependency of otlp recordable, add `Gauge` support for `OtlpMetri…
owent fbfbd46
Add unit test for `OtlpHttpMetricExporter`
owent 3ee89d6
Fix format
owent 4fe3069
Fix unit test `OtlpMetricSerializationTest.ObservableGauge`
owent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| #pragma once | ||
| #ifndef ENABLE_METRICS_PREVIEW | ||
|
|
||
| # include "opentelemetry/sdk/metrics/metric_exporter.h" | ||
|
|
||
| # include "opentelemetry/exporters/otlp/otlp_http_client.h" | ||
|
|
||
| # include "opentelemetry/exporters/otlp/otlp_environment.h" | ||
|
|
||
| # include <chrono> | ||
| # include <cstddef> | ||
| # include <memory> | ||
| # include <string> | ||
|
|
||
| OPENTELEMETRY_BEGIN_NAMESPACE | ||
| namespace exporter | ||
| { | ||
| namespace otlp | ||
| { | ||
|
|
||
| /** | ||
| * Struct to hold OTLP exporter options. | ||
| */ | ||
| struct OtlpHttpMetricExporterOptions | ||
| { | ||
| // The endpoint to export to. By default | ||
| // @see | ||
| // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/otlp.md | ||
| // @see https://github.com/open-telemetry/opentelemetry-collector/tree/main/receiver/otlpreceiver | ||
| std::string url = GetOtlpDefaultHttpMetricEndpoint(); | ||
|
|
||
| // By default, post json data | ||
| HttpRequestContentType content_type = HttpRequestContentType::kJson; | ||
|
|
||
| // If convert bytes into hex. By default, we will convert all bytes but id into base64 | ||
| // This option is ignored if content_type is not kJson | ||
| JsonBytesMappingKind json_bytes_mapping = JsonBytesMappingKind::kHexId; | ||
|
|
||
| // If using the json name of protobuf field to set the key of json. By default, we will use the | ||
| // field name just like proto files. | ||
| bool use_json_name = false; | ||
|
|
||
| // Whether to print the status of the exporter in the console | ||
| bool console_debug = false; | ||
|
|
||
| // TODO: Enable/disable to verify SSL certificate | ||
| std::chrono::system_clock::duration timeout = GetOtlpDefaultMetricTimeout(); | ||
|
|
||
| // Additional HTTP headers | ||
| OtlpHeaders http_headers = GetOtlpDefaultMetricHeaders(); | ||
|
|
||
| # ifdef ENABLE_ASYNC_EXPORT | ||
| // Concurrent requests | ||
| // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/otlp.md#otlpgrpc-concurrent-requests | ||
| std::size_t max_concurrent_requests = 64; | ||
|
|
||
| // Requests per connections | ||
| std::size_t max_requests_per_connection = 8; | ||
| # endif | ||
| }; | ||
|
|
||
| /** | ||
| * The OTLP exporter exports metrics data in OpenTelemetry Protocol (OTLP) format in HTTP. | ||
| */ | ||
| class OtlpHttpMetricExporter final : public opentelemetry::sdk::metrics::MetricExporter | ||
| { | ||
| public: | ||
| /** | ||
| * Create an OtlpHttpMetricExporter with default exporter options. | ||
| */ | ||
| OtlpHttpMetricExporter(); | ||
|
|
||
| /** | ||
| * Create an OtlpHttpMetricExporter with user specified options. | ||
| * @param options An object containing the user's configuration options. | ||
| */ | ||
| OtlpHttpMetricExporter(const OtlpHttpMetricExporterOptions &options); | ||
|
|
||
| opentelemetry::sdk::common::ExportResult Export( | ||
| const opentelemetry::sdk::metrics::ResourceMetrics &data) noexcept override; | ||
|
|
||
| /** | ||
| * Force flush the exporter. | ||
| */ | ||
| bool ForceFlush( | ||
| std::chrono::microseconds timeout = (std::chrono::microseconds::max)()) noexcept override; | ||
|
|
||
| bool Shutdown( | ||
| std::chrono::microseconds timeout = (std::chrono::microseconds::max)()) noexcept override; | ||
|
|
||
| private: | ||
| // Configuration options for the exporter | ||
| const OtlpHttpMetricExporterOptions options_; | ||
|
|
||
| // Object that stores the HTTP sessions that have been created | ||
| std::unique_ptr<OtlpHttpClient> http_client_; | ||
| // For testing | ||
| friend class OtlpHttpMetricExporterTestPeer; | ||
|
|
||
| /** | ||
| * Create an OtlpHttpMetricExporter using the specified http client. | ||
| * Only tests can call this constructor directly. | ||
| * @param http_client the http client to be used for exporting | ||
| */ | ||
| OtlpHttpMetricExporter(std::unique_ptr<OtlpHttpClient> http_client); | ||
| }; | ||
| } // namespace otlp | ||
| } // namespace exporter | ||
| OPENTELEMETRY_END_NAMESPACE | ||
| #endif |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.