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

feat(tracing): inject component ID as instrumentation scope attribute #5286

Conversation

hainenber
Copy link
Contributor

PR Description

Which issue(s) this PR fixes

Fixes #5285

Notes to the Reviewer

PR Checklist

  • CHANGELOG.md updated

@hainenber hainenber requested review from a team and clayton-cornell as code owners September 23, 2023 16:03
@hainenber hainenber force-pushed the inject-component-id-as-instrumentation-scope-attr branch from ae08353 to d0de674 Compare September 23, 2023 16:52
Copy link
Contributor

@clayton-cornell clayton-cornell left a comment

Choose a reason for hiding this comment

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

No docs changes included, so I'll step away from this one :-)

@rfratto
Copy link
Member

rfratto commented Sep 26, 2023

I'm testing this change locally right now, and I'm trying to figure out where the attributes show up in Tempo.

@rfratto
Copy link
Member

rfratto commented Sep 26, 2023

I'm not able to see the instrumentation scope in Tempo; trying to figure out why.

@rfratto
Copy link
Member

rfratto commented Sep 26, 2023

I chatted with the Tempo team and apparently Tempo doesn't support instrumentation scope attributes yet, so setting this would be a no-op for Tempo. For now, we have to decide if this attribute belongs more on the span or on the resource (which Tempo would support today).

WDYT @ptodev @hainenber?

@ptodev
Copy link
Contributor

ptodev commented Sep 26, 2023

We have to decide if this attribute belongs more on the span or on the resource (which Tempo would support today).

I suppose a span attribute would be more appropriate. As defined in the spec, a "resource" is supposed to combine multiple instrumentation scopes. Hence it doesn't seem appropriate to assume that only one instrumentation scope is part of the resource.

I think we should proceed like this:

  • Add span attributes with the full componentID/controllerID as we do now.
    • Those attributes will include the component instance name. E.g. they could look like otelcol.receiver.otlp.default.
    • We could keep those attributes in the long term, because specifying the component instance makes more sense as a span attribute than as an instrumentation scope.
  • Add instrumentation scope which does not include the component instance name
    • Those attributes will not include the component instance name. E.g. they could look like otelcol.receiver.otlp. I think this is more in line with Otel's expectations.
    • Even though Tempo doesn't support instrumentation scope, I see no harm in adding it. I guess Tempo will just ignore it? And Tempo will presumably support it soon anyway?

In the long run, after Tempo supports instrumentation scope, we could even optimise by deprecating the grafana_agent.component_id span attribute and instead having just a span attribute with the component instance name (e.g. "default" instead of "otelcol.receiver.otlp.default"). Maybe this would speed up some queries?

BTW I wonder whether we should use the source code attribute conventions as well. I cannot think of a clean way to use it. We could have "code.namespace" = "grafana_agent.component.otelcol.exporter.loadbalancing", but I think it's easier just to have a "grafana_agent.component_id" = "otelcol.receiver.otlp.default". That way we also specify that "default" is the component instance name.

@hainenber
Copy link
Contributor Author

hi there, long week for me, hence the long time for reply :)

First of all, thanks @rfratto for going to extended length to reach out Tempo team to test it out. That was awesome!

Basically, I agree with @ptodev's proposal here. We can keep the span attribute as is and try to add instrumentation scope without the component's instance name (I suppose that means we need to omit the last dot-separated part, e.g. "a.b.c" -> "a.b")

Although Tempo might not support instrumentation scope attribute, other OTEL-compatible tracing backend might already support it and so it could be more than just no-op ;)

Let me implement and test the proposal. Will keep you posted

@hainenber hainenber force-pushed the inject-component-id-as-instrumentation-scope-attr branch from d0de674 to dc237d6 Compare October 7, 2023 15:26
@hainenber hainenber force-pushed the inject-component-id-as-instrumentation-scope-attr branch from dc237d6 to 6f30a7d Compare October 7, 2023 15:27
@hainenber
Copy link
Contributor Author

Hi folks, I've made a draft implementation as suggested above. PTAL when you have time. Thanks!

Comment on lines +46 to +51
// Inject the component name as instrumentation scope attribute.
// This would not have component's exact ID, aligning with OTEL's definition
if wp.id != "" {
otelComponentName := strings.TrimSuffix(wp.id, filepath.Ext(wp.id))
options = append(options, trace.WithInstrumentationAttributes(attribute.String(wp.spanName, otelComponentName)))
}
Copy link
Member

Choose a reason for hiding this comment

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

Does the exact ID of the component still get set on the span?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the old function isn't removed, yet ;)

Copy link
Member

Choose a reason for hiding this comment

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

Cool, just double checking :)

Copy link
Member

@rfratto rfratto left a comment

Choose a reason for hiding this comment

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

Thanks for your work!

@rfratto rfratto merged commit 93cb6c3 into grafana:main Oct 11, 2023
6 checks passed
@github-actions github-actions bot added the frozen-due-to-age Locked due to a period of inactivity. Please open new issues or PRs if more discussion is needed. label Feb 21, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
frozen-due-to-age Locked due to a period of inactivity. Please open new issues or PRs if more discussion is needed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Traces emitted by Flow components should set component ID as a instrumentation scope attribute
4 participants