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

Method to add service_name to all spans #34

Merged
merged 7 commits into from May 3, 2021
Merged

Conversation

isobelhooper
Copy link
Contributor

This commit adds a with_service_name method to PipelineBuilder and Exporter to allow users to set the service name in one place, following the behaviour of the Datadog and Zipkin exporters.

It also sets a default service.name value if the user does not configure one.


I noticed that the doc test for with_trace_config already handles this particular case, but having a method specifically for it would match other exporters, and would also make it possible to supply a default value.

It's useful to have a way to set the service name for all spans at once,
rather than having to set it every time.

This commit adds a with_service_name method to PipelineBuilder
and Exporter to allow users to set the service name in one place,
following the behaviour of the official DataDog and Zipkin exporters.

It also sets a default service_name if the user does not configure one.
@frigus02
Copy link
Owner

frigus02 commented Apr 6, 2021

Thanks a lot. I think this makes sense to me. I want to have another look at the spec to remind myself how service.name is supposed to work. Will try to do this tomorrow.

@frigus02
Copy link
Owner

frigus02 commented Apr 7, 2021

I looked a bit closer now. My thoughts are:

  • Defaulting to "unknown_service" is good. According to the spec we should handle this in the SDK somehow.

  • Both the Zipkin and Jaeger exporter should use the service.name from the span attributes. I don't think they do, so they are currently not spec compliant.

For Application Insights we use the service.name to set the Cloud role context tag. As far as I know this tag is optional. But I don't know if there is a best practice around setting this to some default value. If there is, it definitely makes sense to add that here.

Based on this my feeling is that:

  • We should add the default value for service.name to opentelemetry-rust.

  • We should fix the Zipkin and Jaeger exporter so they take the service.name attribute into account.

  • We can add a convenience function to the pipeline builder here to set the service name. I think I would prefer if that would add the service.name to the trace config. But I think this might not work because the resource is behind an Arc.

I'm happy to help with any of those.

What do you think?

@isobelhooper
Copy link
Contributor Author

Thank you for your detailed reply, and apologies for not replying sooner!

Based on this my feeling is that:

  • We should add the default value for service.name to opentelemetry-rust.
  • We should fix the Zipkin and Jaeger exporter so they take the service.name attribute into account.
  • We can add a convenience function to the pipeline builder here to set the service name. I think I would prefer if that would add the service.name to the trace config. But I think this might not work because the resource is behind an Arc.

I'm happy to help with any of those.

What do you think?

I've talked through this with my coworker who knows more Rust than I do (I'm afraid I'm quite new at it), and he and I can work on rewriting the convenience function for the pipeline builder so that it adds service.name to the trace config.

Based on the specification for resources, it looks like the correct behaviour if someone sets service.name in both with_trace_config and with_service_name is to take the name from the later of the calls, so we'll bear that in mind.

The other two changes (adding the correct behaviour to opentelemetry-rust, and fixing the Zipkin and Jaeger exporters) both sound good, but I'm not sure I have the bandwidth or the knowledge of Rust to help with them.

Would it be okay to implement the spec-compliant default in opentelemetry-application-insights for now, and then move it over to opentelemetry-rust later? I can include that as part of this PR as well.

johnchildren and others added 6 commits April 29, 2021 15:14
Rather than relying on a property on PipelineBuilder, instead set the
service.name in the sdk::Config by merging sdk::Resouce properties. This
is also a change to the behavior of with_config.
Co-authored-by: isobelhooper <isobel.hooper@cambridgequantum.com>
@frigus02
Copy link
Owner

frigus02 commented May 3, 2021

Hi @isobelhooper, sorry for the delayed response. This looks great, thank you. I'm going to create a new release with this soon.

Regarding the Zipkin/Jaeger changes: don't worry about it. It's cool if you happen to find the time. I'm sure otherwise someone else is going to do it eventually 🙂

Copy link
Owner

@frigus02 frigus02 left a comment

Choose a reason for hiding this comment

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

Just found 2 minor things that we could write differently. I might change that later. But it doesn't block this.

src/lib.rs Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
@frigus02 frigus02 merged commit 82bf375 into frigus02:main May 3, 2021
@frigus02
Copy link
Owner

frigus02 commented May 3, 2021

I just pushed version 0.14.0. Thanks for working on this! 🙂

Comment on lines +302 to +303
/// Assign the service name under which to group traces by adding a service.name
/// `sdk::Resource` or overriding a previous setting of it.
Copy link
Owner

Choose a reason for hiding this comment

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

Please note that "overriding a previous setting" is not true with the current version 0.13.0 of opentelemetry. We just updated the sdk::Resource::merge logic to reflect the latest spec in open-telemetry/opentelemetry-rust#537. This will be included in the next release, though.

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.

None yet

3 participants