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

[confighttp]: add an option to add span formatter #11230

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

VihasMakwana
Copy link
Contributor

@VihasMakwana VihasMakwana commented Sep 20, 2024

Description

This PR adds a new server option to modify span formatter.
it also updates otlpreceiver to use the option.

Link to tracking issue

Fixes #9382

Testing

Added.


component.ID is not available in this section of code. Since ToServer is intended to be general and can be used by extensions, receivers, and exporters, modifying it to accept internal.Settings would introduce a breaking change, which I'm not comfortable with. Therefore, I believe it would be better to provide an option to change the prefix instead.

@VihasMakwana VihasMakwana requested a review from a team as a code owner September 20, 2024 14:40
Copy link

codecov bot commented Sep 20, 2024

Codecov Report

Attention: Patch coverage is 94.44444% with 1 line in your changes missing coverage. Please review.

Project coverage is 91.64%. Comparing base (9d2685f) to head (2deac0e).

Files with missing lines Patch % Lines
receiver/otlpreceiver/otlp.go 75.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #11230      +/-   ##
==========================================
+ Coverage   91.62%   91.64%   +0.01%     
==========================================
  Files         442      442              
  Lines       23776    23793      +17     
==========================================
+ Hits        21785    21804      +19     
+ Misses       1619     1618       -1     
+ Partials      372      371       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@VihasMakwana
Copy link
Contributor Author

@bogdandrutu @open-telemetry/collector-approvers I'd appreciate your review on this!

Copy link
Member

@andrzej-stencel andrzej-stencel left a comment

Choose a reason for hiding this comment

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

Other than the one nit, this looks sensible to me. Still definitely needs a look from @codeboten or @bogdandrutu who have more insight into this functionality.

config/confighttp/confighttp.go Outdated Show resolved Hide resolved
@VihasMakwana
Copy link
Contributor Author

@bogdandrutu @codeboten The CI looks good now. PTAL!

Copy link
Member

@mx-psi mx-psi left a comment

Choose a reason for hiding this comment

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

LGTM. @bogdandrutu since this is related to a TODO you added, would you mind double checking that this looks good?

@VihasMakwana
Copy link
Contributor Author

@bogdandrutu @open-telemetry/collector-maintainers can someone take a look here?

return r.URL.Path
}),
otelhttp.WithMeterProvider(settings.LeveledMeterProvider(configtelemetry.LevelDetailed)),
}

// Enable OpenTelemetry observability plugin.
// TODO: Consider to use component ID string as prefix for all the operations.
handler = otelhttp.NewHandler(handler, "", otelOpts...)
handler = otelhttp.NewHandler(handler, serverOpts.spanPrefix, otelOpts...)
Copy link
Member

@dmathieu dmathieu Oct 11, 2024

Choose a reason for hiding this comment

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

This parameter is not a span prefix. It's the operation name.
See https://pkg.go.dev/go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp#NewHandler
How about naming the option WithOperationName instead of WithSpanPrefix?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dmathieu I understand your perspective, but we use spanPrefix specifically as a prefix for an operation in this context, using otelhttp.WithSpanNameFormatter

otelhttp.WithSpanNameFormatter(func(operation string, r *http.Request) string {
if len(operation) > 0 {
return fmt.Sprintf("%s:%s", operation, r.URL.Path)
}
return r.URL.Path
}),

That's why I named it WithSpanPrefix.


Using WithOperationName might suggest that the option is meant for naming the operation itself, which isn’t accurate. Instead, it serves as a prefix.

For eg.
For example, if you specify WithSpanPrefix("foo") and make an HTTP request to http://host:port/path/bar, the tracer would be named foo:/path/bar.

Does that help clarify?

@VihasMakwana VihasMakwana requested a review from dmathieu October 11, 2024 14:30
Comment on lines 414 to 420
// WithSpanPrefix creates a span prefixed with the specified name.
// Ideally, this prefix should be the component's ID.
func WithSpanPrefix(spanPrefix string) ToServerOption {
return toServerOptionFunc(func(opts *toServerOptions) {
opts.spanPrefix = spanPrefix
})
}

Choose a reason for hiding this comment

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

We should make it a bit more generic and accept otelhttp.Option or at least accept exactly same formatter? You may now want this, but later people may want other things, etc.

Choose a reason for hiding this comment

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

The problem though, is that otelhttp is not stable, and we are looking to mark this stable soon. So I think we may not be able to accept this until otelhttp is marked stable.

Copy link
Member

Choose a reason for hiding this comment

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

@dmathieu since you are around, any idea of whether otelhttp will be marked stable any time soon?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sfc-gh-bdrutu @bogdandrutu can you take a look now? I've made it more generic.

Copy link
Member

Choose a reason for hiding this comment

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

any idea of whether otelhttp will be marked stable any time soon?

That is not on our radar at the moment. However, we are committed to keeping the API stable, or providing deprecation warnings for at least two versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sfc-gh-bdrutu @bogdandrutu can you take a look?

Copy link
Member

Choose a reason for hiding this comment

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

A possible way around this is to move the option to a separate module. We are discussing this in #11769

@VihasMakwana VihasMakwana changed the title [confighttp]: add an option to add span prefix [confighttp]: add an option to add span formatter Oct 15, 2024
@VihasMakwana VihasMakwana changed the title [confighttp]: add an option to add span formatter [confighttp]: add an option to add span formater Oct 21, 2024
@VihasMakwana VihasMakwana changed the title [confighttp]: add an option to add span formater [confighttp]: add an option to add span formatter Oct 21, 2024
Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Nov 16, 2024
@songy23 songy23 removed the Stale label Nov 20, 2024
Copy link

@sfc-gh-bdrutu sfc-gh-bdrutu left a comment

Choose a reason for hiding this comment

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

I have the concern that we really on the "formater" definition from the httptrace which is not stable. The reason this is a concern compare to using that package, is because be are exposing this in our public API.

Also: The API surface (especially because things are stable now) should be minimal.

# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []

Choose a reason for hiding this comment

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

api

@@ -556,6 +564,15 @@ func maxRequestBodySizeInterceptor(next http.Handler, maxRecvSize int64) http.Ha
})
}

func PrefixFormatter(prefix string) func(string, *http.Request) string {

Choose a reason for hiding this comment

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

why public?

if r.serverHTTP, err = r.cfg.HTTP.ToServer(ctx, host, r.settings.TelemetrySettings, httpMux, confighttp.WithErrorHandler(errorHandler)); err != nil {
if r.serverHTTP, err = r.cfg.HTTP.ToServer(ctx, host, r.settings.TelemetrySettings, httpMux,
confighttp.WithErrorHandler(errorHandler),
confighttp.WithSpanFormatter(confighttp.PrefixFormatter(r.settings.ID.String())),
Copy link
Member

Choose a reason for hiding this comment

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

Is this a breaking change? If this is merged will the spans that the otlpreceiver creates about itself have new names?

Copy link
Member

Choose a reason for hiding this comment

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

@TylerHelmuth Is your concern that we should not do this if it is a breaking change?

// Ideally, this prefix in span name should be the component's ID.
func WithSpanFormatter(formater func(string, *http.Request) string) ToServerOption {
return toServerOptionFunc(func(opts *toServerOptions) {
opts.formater = formater
Copy link
Member

Choose a reason for hiding this comment

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

if formater != nil {
	// ....
}

if r.serverHTTP, err = r.cfg.HTTP.ToServer(ctx, host, r.settings.TelemetrySettings, httpMux, confighttp.WithErrorHandler(errorHandler)); err != nil {
if r.serverHTTP, err = r.cfg.HTTP.ToServer(ctx, host, r.settings.TelemetrySettings, httpMux,
confighttp.WithErrorHandler(errorHandler),
confighttp.WithSpanFormatter(confighttp.PrefixFormatter(r.settings.ID.String())),
Copy link
Member

Choose a reason for hiding this comment

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

If we want to do this, we can use #11769 now :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[config/confighttp] Resolve the TODO on confighttp.go related to prefixing operations with component id.
9 participants