-
Notifications
You must be signed in to change notification settings - Fork 244
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
fix(exporter/otlp): align endpoint environment varaible handling with spec #1506
Changes from 5 commits
62a310c
c262ced
960c500
a8c2313
87b4137
40204f9
6de7fa5
c21727e
f2748b7
90802ee
3a05c3d
e4d31d6
316b565
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,22 +47,16 @@ def self.ssl_verify_mode | |
end | ||
end | ||
|
||
def initialize(endpoint: OpenTelemetry::Common::Utilities.config_opt('OTEL_EXPORTER_OTLP_TRACES_ENDPOINT', 'OTEL_EXPORTER_OTLP_ENDPOINT', default: 'http://localhost:4318/v1/traces'), | ||
def initialize(endpoint: nil, | ||
certificate_file: OpenTelemetry::Common::Utilities.config_opt('OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE', 'OTEL_EXPORTER_OTLP_CERTIFICATE'), | ||
ssl_verify_mode: Exporter.ssl_verify_mode, | ||
headers: OpenTelemetry::Common::Utilities.config_opt('OTEL_EXPORTER_OTLP_TRACES_HEADERS', 'OTEL_EXPORTER_OTLP_HEADERS', default: {}), | ||
compression: OpenTelemetry::Common::Utilities.config_opt('OTEL_EXPORTER_OTLP_TRACES_COMPRESSION', 'OTEL_EXPORTER_OTLP_COMPRESSION', default: 'gzip'), | ||
timeout: OpenTelemetry::Common::Utilities.config_opt('OTEL_EXPORTER_OTLP_TRACES_TIMEOUT', 'OTEL_EXPORTER_OTLP_TIMEOUT', default: 10), | ||
metrics_reporter: nil) | ||
raise ArgumentError, "invalid url for OTLP::Exporter #{endpoint}" unless OpenTelemetry::Common::Utilities.valid_url?(endpoint) | ||
@uri = determine_url(endpoint) | ||
raise ArgumentError, "unsupported compression key #{compression}" unless compression.nil? || %w[gzip none].include?(compression) | ||
|
||
@uri = if endpoint == ENV['OTEL_EXPORTER_OTLP_ENDPOINT'] | ||
URI.join(endpoint, 'v1/traces') | ||
else | ||
URI(endpoint) | ||
end | ||
|
||
@http = http_connection(@uri, ssl_verify_mode, certificate_file) | ||
|
||
@path = @uri.path | ||
|
@@ -386,6 +380,42 @@ def as_otlp_any_value(value) | |
result | ||
end | ||
|
||
# Returns the url used by the exporter based on the precedence defined in the specification: | ||
# https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md#endpoint-urls-for-otlphttp | ||
# | ||
# @param [String, nil] endpoint | ||
# @return [URI::Generic] | ||
def determine_url(endpoint) | ||
if !endpoint.nil? | ||
# Use endpoint provided via argument as-is | ||
parse_url_or_raise(endpoint) | ||
elsif !ENV['OTEL_EXPORTER_OTLP_TRACES_ENDPOINT'].nil? | ||
# Use signal-specific endpoint as-is | ||
parse_url_or_raise(ENV['OTEL_EXPORTER_OTLP_TRACES_ENDPOINT']) | ||
elsif !ENV['OTEL_EXPORTER_OTLP_ENDPOINT'].nil? | ||
# Append v1/traces only if the non-signal specific env var is set. | ||
non_signal_specific_endpoint = ENV['OTEL_EXPORTER_OTLP_ENDPOINT'] | ||
# append '/' if not present | ||
non_signal_specific_endpoint += '/' unless non_signal_specific_endpoint.end_with?('/') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not necessary. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, I could be wrong (this is the first time I'm using ruby). I also initially assumed it does, but trying it out in
drops |
||
begin | ||
URI.join(non_signal_specific_endpoint, 'v1/traces') | ||
rescue URI::InvalidURIError | ||
raise ArgumentError, "invalid url for OTLP::Exporter #{non_signal_specific_endpoint}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I strongly prefer to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm re-raising in the constructor now to hide the private method f2748b7, couldn't pull everything in the constructor unfortunately as complexity ended up being too high and rubocop failed. |
||
end | ||
else | ||
# use default in all other cases | ||
parse_url_or_raise('http://localhost:4318/v1/traces') | ||
end | ||
end | ||
|
||
def parse_url_or_raise(endpoint) | ||
raise ArgumentError, "invalid url for OTLP::Exporter #{endpoint}" if endpoint.nil? || endpoint.strip.empty? | ||
|
||
URI(endpoint) | ||
rescue URI::InvalidURIError | ||
raise ArgumentError, "invalid url for OTLP::Exporter #{endpoint}" | ||
end | ||
|
||
def prepare_headers(config_headers) | ||
headers = case config_headers | ||
when String then parse_headers(config_headers) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this captures the essence of the rules while raising as close to the public interface as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's better (using some language features that I didn't know yet, nice 😄). Thanks for the suggestion 🙌
Accepted the suggestion in 40204f9, but included appending
/
(see #1506 (comment))There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to make some changes to make this pass the rubocop rules as complexity was too high f2748b7