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

Traces server span and url fixes #80

Merged
merged 2 commits into from
Apr 24, 2023
Merged

Conversation

grcevski
Copy link
Contributor

This PR changes the type of the external span in traces to be SpanKind = SpanKindServer. When we have the external span as server, we are able to produce metrics with just trace spans. The Tempo span metric generator is able to produce metrics.

While testing this functionality I noticed a small issue when using the OTEL_EXPORTER_OTLP_TRACES_ENDPOINT and the OTEL_EXPORTER_OTLP_METRICS_ENDPOINT environment variables. As per the OTel spec, if we are using the non-signal specific environment variable (i.e. not using OTEL_EXPORTER_OTLP_ENDPOINT) we need to pass in the full URL for the traces or the metrics, including the /v1/traces and /v1/metrics suffixes -> https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md#example-2. However, if our code noticed anything in the URL path (other than /), we'd append /v1/traces|metrics, technically, appending twice.

To fix this issue, I changed the code to not append /v1/traces|metrics if that's the suffix. I believe this will work in all cases.

@grcevski grcevski added the bug Something isn't working label Apr 21, 2023
@grcevski grcevski requested a review from mariomac April 21, 2023 19:03
@grcevski grcevski self-assigned this Apr 21, 2023
@codecov-commenter
Copy link

codecov-commenter commented Apr 21, 2023

Codecov Report

Merging #80 (c88218c) into main (b13d1f6) will increase coverage by 1.02%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main      #80      +/-   ##
==========================================
+ Coverage   45.71%   46.74%   +1.02%     
==========================================
  Files          15       15              
  Lines        1166     1166              
==========================================
+ Hits          533      545      +12     
+ Misses        580      572       -8     
+ Partials       53       49       -4     
Flag Coverage Δ
unittests 46.74% <100.00%> (+1.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/export/otel/metrics.go 78.33% <100.00%> (+5.00%) ⬆️
pkg/export/otel/traces.go 73.48% <100.00%> (+4.54%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@mariomac
Copy link
Contributor

Good catch! Thanks for fixing.

@@ -180,7 +181,7 @@ func getMetricEndpointOptions(cfg *MetricsConfig) ([]otlpmetrichttp.Option, erro
if murl.Scheme == "http" || murl.Scheme == "unix" {
opts = append(opts, otlpmetrichttp.WithInsecure())
}
if len(murl.Path) > 0 && murl.Path != "/" {
if len(murl.Path) > 0 && murl.Path != "/" && !strings.HasSuffix(murl.Path, "/v1/metrics") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmm I'm thinking in the case of someone willing to pass:

OTEL_EXPORTER_OTLP_METRICS_ENDPOINT=https://foo:8080/my/metrics, then the code will set the endpoint as https://foo:8080/my/metrics/v1/metrics. But it should remain untouched in that case, right?

I think then the code should be something like:

if cfg.MetricsEndpoint == "" && murl.Path != "/" {
    opts = append(opts, otlpmetrichttp.WithURLPath(murl.Path+"/v1/metrics"))
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Re-reviewing the OTEL spec: https://opentelemetry.io/docs/concepts/sdk-configuration/otlp-exporter-configuration/#otel_exporter_otlp_endpoint

It says that the OTEL_EXPORTER_OTLP_METRICS_ENDPOINT MUST end with /v1/traces so it is fine if, instead of returning an error, we silently add the path.

@@ -186,8 +187,10 @@ func getTracesEndpointOptions(cfg *TracesConfig) ([]otlptracehttp.Option, error)
if murl.Scheme == "http" || murl.Scheme == "unix" {
opts = append(opts, otlptracehttp.WithInsecure())
}
if len(murl.Path) > 0 && murl.Path != "/" {

if len(murl.Path) > 0 && murl.Path != "/" && !strings.HasSuffix(murl.Path, "/v1/traces") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as before.

@grcevski grcevski merged commit 94ba5fe into grafana:main Apr 24, 2023
2 checks passed
@grcevski
Copy link
Contributor Author

Thanks Mario!

@grcevski grcevski deleted the traces_server branch April 24, 2023 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants