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 12 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.

Copy link

codecov bot commented Sep 20, 2024

Codecov Report

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

Project coverage is 92.15%. Comparing base (a7d019f) to head (4fe1105).

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   92.15%   92.15%           
=======================================
  Files         432      432           
  Lines       20253    20265   +12     
=======================================
+ Hits        18664    18676   +12     
  Misses       1228     1228           
  Partials      361      361           

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

@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?

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.

@VihasMakwana VihasMakwana changed the title [confighttp]: add an option to add span prefix [confighttp]: add an option to add span formatter Oct 15, 2024
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.
6 participants