-
Notifications
You must be signed in to change notification settings - Fork 5.5k
opentelemetry tracer: add OTLP/HTTP exporter #29207
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
wbpcode
merged 49 commits into
envoyproxy:main
from
dynatrace-oss-contrib:otlp-http-exporter-continue
Oct 18, 2023
Merged
Changes from 16 commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
c6ece86
Refactor gRPC exporter to use general base class we can later reuse
AlexanderEllis b59764e
Update OpenTelemetryConfig with HTTP-related config
AlexanderEllis ad99eb0
Write and wire up HTTP trace exporter
AlexanderEllis 15fa601
Code formatting
AlexanderEllis 8feddf1
Proto format
AlexanderEllis 0a4f183
Add basic tests
AlexanderEllis 5e4f9a6
code format
AlexanderEllis c058475
Add additional counters for http exporter and test
AlexanderEllis 1a6d2fc
Formatting
AlexanderEllis bf51b6e
Coverage improvements
AlexanderEllis 40cd7fc
Formatting
AlexanderEllis 0a20370
Add higher level Driver test for HTTP exporting
AlexanderEllis a498727
More formatting
AlexanderEllis ccf877c
Clang tidy
AlexanderEllis 6793f2f
Refactor config and add HTTP headers
joaopgrassi ab935a7
Modify tests
joaopgrassi 03edac8
Fix lint errors
joaopgrassi c3e8b81
Revert oneof in proto config
joaopgrassi f507a0f
PR suggestions
joaopgrassi 6815fb5
Add HttpService config type
joaopgrassi ec2a0d5
Merge remote-tracking branch 'upstream/main' into otlp-http-exporter-…
joaopgrassi 8d1d23a
Fix format issues
joaopgrassi f883976
Fix lint/format/docs issues
joaopgrassi 0b5b8bf
Merge remote-tracking branch 'upstream/main' into otlp-http-exporter-…
joaopgrassi 2da074d
Merge remote-tracking branch 'upstream/main' into otlp-http-exporter-…
joaopgrassi 1389804
Merge remote-tracking branch 'upstream/main' into otlp-http-exporter-…
joaopgrassi 2b6b267
Hostname -> Authority
joaopgrassi 3be83f8
Use HttpUri type
joaopgrassi 38adbf1
Merge remote-tracking branch 'upstream/main' into otlp-http-exporter-…
joaopgrassi 2a5d544
PR suggestions
joaopgrassi 935ad0c
Improve log messages
joaopgrassi 9ec6806
Fix format
joaopgrassi 9b5e47a
Merge remote-tracking branch 'upstream/main' into otlp-http-exporter-…
joaopgrassi c0f39d7
Merge remote-tracking branch 'upstream/main' into otlp-http-exporter-…
joaopgrassi f852967
PR suggestions
joaopgrassi 7ea4d0b
PR suggestions
joaopgrassi ba5d943
Revert stats for http exporter
joaopgrassi 38bd4ac
Fix spelling
joaopgrassi 3d07358
Merge remote-tracking branch 'upstream/main' into otlp-http-exporter-…
joaopgrassi ec3911b
Merge remote-tracking branch 'upstream/main' into otlp-http-exporter-…
joaopgrassi 8c7ca70
Add changelog
joaopgrassi efcd78a
Merge remote-tracking branch 'upstream/main' into otlp-http-exporter-…
joaopgrassi e339153
Properly manage in-flight http requests in the exporter
joaopgrassi e7932fb
Merge remote-tracking branch 'upstream/main' into otlp-http-exporter-…
joaopgrassi aacb3f4
Add proto migrate oneof annotation
joaopgrassi c8f74c3
Clarify http headers do not support formatting
joaopgrassi e00f32b
Merge remote-tracking branch 'upstream/main' into otlp-http-exporter-…
joaopgrassi cb08695
Prepare headers when creating the HTTP exporter
joaopgrassi 97f6870
Revert test change
joaopgrassi 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
86 changes: 86 additions & 0 deletions
86
source/extensions/tracers/opentelemetry/http_trace_exporter.cc
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,86 @@ | ||
| #include "http_trace_exporter.h" | ||
|
joaopgrassi marked this conversation as resolved.
Outdated
|
||
|
|
||
| #include <chrono> | ||
| #include <memory> | ||
| #include <string> | ||
|
|
||
| #include "source/common/common/logger.h" | ||
| #include "source/common/protobuf/protobuf.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace Tracers { | ||
| namespace OpenTelemetry { | ||
|
|
||
| OpenTelemetryHttpTraceExporter::OpenTelemetryHttpTraceExporter( | ||
| Upstream::ClusterManager& cluster_manager, | ||
| envoy::config::trace::v3::OpenTelemetryConfig::HttpConfig http_config, | ||
| OpenTelemetryTracerStats& tracing_stats) | ||
| : cluster_manager_(cluster_manager), http_config_(http_config), tracing_stats_(tracing_stats) {} | ||
|
|
||
| bool OpenTelemetryHttpTraceExporter::log(const ExportTraceServiceRequest& request) { | ||
|
|
||
|
joaopgrassi marked this conversation as resolved.
|
||
| std::string request_body; | ||
|
|
||
| const auto ok = request.SerializeToString(&request_body); | ||
| if (!ok) { | ||
|
joaopgrassi marked this conversation as resolved.
|
||
| ENVOY_LOG(warn, "Error while serializing the binary proto ExportTraceServiceRequest."); | ||
| return false; | ||
| } | ||
|
|
||
| Http::RequestMessagePtr message = std::make_unique<Http::RequestMessageImpl>(); | ||
| message->headers().setReferenceMethod(Http::Headers::get().MethodValues.Post); | ||
|
joaopgrassi marked this conversation as resolved.
|
||
| message->headers().setReferenceContentType(Http::Headers::get().ContentTypeValues.Protobuf); | ||
|
|
||
| // If traces_path is omitted, send to /v1/traces by default | ||
| if (http_config_.traces_path().empty()) { | ||
| message->headers().setPath(TRACES_PATH); | ||
| } else { | ||
| message->headers().setPath(http_config_.traces_path()); | ||
| } | ||
|
joaopgrassi marked this conversation as resolved.
|
||
|
|
||
| // TODO: Can we get the hostname that is configured in the cluster "socker_address" field? | ||
| message->headers().setHost(http_config_.hostname()); | ||
|
joaopgrassi marked this conversation as resolved.
Outdated
|
||
|
|
||
| // add all custom headers to the request | ||
|
joaopgrassi marked this conversation as resolved.
Outdated
|
||
| for (const envoy::config::core::v3::HeaderValue& header : http_config_.headers()) { | ||
| message->headers().setCopy(Http::LowerCaseString(header.key()), header.value()); | ||
| } | ||
|
|
||
| message->body().add(request_body); | ||
|
|
||
| const auto thread_local_cluster = | ||
| cluster_manager_.getThreadLocalCluster(http_config_.cluster_name()); | ||
| if (thread_local_cluster == nullptr) { | ||
| ENVOY_LOG(warn, "Thread local cluster not found for collector."); | ||
| return false; | ||
| } | ||
|
|
||
| std::chrono::milliseconds timeout = std::chrono::duration_cast<std::chrono::milliseconds>( | ||
| std::chrono::nanoseconds(http_config_.timeout().nanos())); | ||
| Http::AsyncClient::Request* http_request = thread_local_cluster->httpAsyncClient().send( | ||
| std::move(message), *this, Http::AsyncClient::RequestOptions().setTimeout(timeout)); | ||
| tracing_stats_.http_reports_sent_.inc(); | ||
|
|
||
| return http_request; | ||
|
wbpcode marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| void OpenTelemetryHttpTraceExporter::onSuccess(const Http::AsyncClient::Request&, | ||
| Http::ResponseMessagePtr&& message) { | ||
| tracing_stats_.http_reports_success_.inc(); | ||
| const auto response_code = message->headers().Status()->value().getStringView(); | ||
| if (response_code != "200") { | ||
| ENVOY_LOG(warn, "response code: {}", response_code); | ||
|
joaopgrassi marked this conversation as resolved.
Outdated
|
||
| } | ||
| } | ||
|
|
||
| void OpenTelemetryHttpTraceExporter::onFailure(const Http::AsyncClient::Request&, | ||
| Http::AsyncClient::FailureReason) { | ||
| ENVOY_LOG(debug, "Request failed."); | ||
|
joaopgrassi marked this conversation as resolved.
Outdated
|
||
| tracing_stats_.http_reports_failed_.inc(); | ||
| } | ||
|
|
||
| } // namespace OpenTelemetry | ||
| } // namespace Tracers | ||
| } // namespace Extensions | ||
| } // namespace Envoy | ||
54 changes: 54 additions & 0 deletions
54
source/extensions/tracers/opentelemetry/http_trace_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,54 @@ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "envoy/config/core/v3/http_uri.pb.h" | ||
| #include "envoy/config/trace/v3/opentelemetry.pb.h" | ||
| #include "envoy/upstream/cluster_manager.h" | ||
|
|
||
| #include "source/common/common/logger.h" | ||
| #include "source/common/http/async_client_impl.h" | ||
| #include "source/common/http/async_client_utility.h" | ||
| #include "source/common/http/headers.h" | ||
| #include "source/common/http/message_impl.h" | ||
| #include "source/common/http/utility.h" | ||
|
|
||
| #include "opentelemetry/proto/collector/trace/v1/trace_service.pb.h" | ||
| #include "trace_exporter.h" | ||
| #include "tracer_stats.h" | ||
|
joaopgrassi marked this conversation as resolved.
Outdated
|
||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace Tracers { | ||
| namespace OpenTelemetry { | ||
|
|
||
| /** | ||
| * Exporter for OTLP traces over HTTP. | ||
| */ | ||
| class OpenTelemetryHttpTraceExporter : public OpenTelemetryTraceExporter, | ||
| public Http::AsyncClient::Callbacks { | ||
| public: | ||
| OpenTelemetryHttpTraceExporter( | ||
| Upstream::ClusterManager& cluster_manager, | ||
| envoy::config::trace::v3::OpenTelemetryConfig::HttpConfig http_config, | ||
| OpenTelemetryTracerStats& tracing_stats); | ||
|
|
||
| // The default path to use when OpenTelemetryConfig::HttpConfig::traces_path is empty | ||
| const Http::LowerCaseString TRACES_PATH{"/v1/traces"}; | ||
|
joaopgrassi marked this conversation as resolved.
Outdated
|
||
|
|
||
| bool log(const ExportTraceServiceRequest& request) override; | ||
|
|
||
| // Http::AsyncClient::Callbacks. | ||
| void onSuccess(const Http::AsyncClient::Request&, Http::ResponseMessagePtr&&) override; | ||
| void onFailure(const Http::AsyncClient::Request&, Http::AsyncClient::FailureReason) override; | ||
| void onBeforeFinalizeUpstreamSpan(Tracing::Span&, const Http::ResponseHeaderMap*) override {} | ||
|
|
||
| private: | ||
| Upstream::ClusterManager& cluster_manager_; | ||
| envoy::config::trace::v3::OpenTelemetryConfig::HttpConfig http_config_; | ||
| OpenTelemetryTracerStats& tracing_stats_; | ||
|
joaopgrassi marked this conversation as resolved.
Outdated
|
||
| }; | ||
|
|
||
| } // namespace OpenTelemetry | ||
| } // namespace Tracers | ||
| } // namespace Extensions | ||
| } // namespace Envoy | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| #pragma once | ||
|
|
||
| #include "source/common/common/logger.h" | ||
|
|
||
| #include "opentelemetry/proto/collector/trace/v1/trace_service.pb.h" | ||
|
|
||
| using opentelemetry::proto::collector::trace::v1::ExportTraceServiceRequest; | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace Tracers { | ||
| namespace OpenTelemetry { | ||
|
|
||
| class OpenTelemetryTraceExporter : public Logger::Loggable<Logger::Id::tracing> { | ||
|
joaopgrassi marked this conversation as resolved.
|
||
| public: | ||
| virtual ~OpenTelemetryTraceExporter() = default; | ||
|
|
||
| virtual bool log(const ExportTraceServiceRequest& request) = 0; | ||
|
joaopgrassi marked this conversation as resolved.
|
||
| }; | ||
|
|
||
| using OpenTelemetryTraceExporterPtr = std::unique_ptr<OpenTelemetryTraceExporter>; | ||
|
|
||
| } // namespace OpenTelemetry | ||
| } // namespace Tracers | ||
| } // namespace Extensions | ||
| } // namespace Envoy | ||
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
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.