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

tracing_attributes: Add an option to explicitly set parent span in #[instrument] #2021

Closed
jaskij opened this issue Mar 24, 2022 · 3 comments · Fixed by #2091
Closed

tracing_attributes: Add an option to explicitly set parent span in #[instrument] #2021

jaskij opened this issue Mar 24, 2022 · 3 comments · Fixed by #2091
Labels
crate/attributes Related to the `tracing-attributes` crate good first issue Good for newcomers kind/feature New feature or request

Comments

@jaskij
Copy link

jaskij commented Mar 24, 2022

Feature Request

Crates

tracing_attributes

Motivation

Sometimes it's useful to be able to set the parent span when using this macro. One use case would be for structs which have their own span and want to instrument their methods.

Proposal

Add a new argument to tracing_attributes::instrument to allow explicitly setting the parent span, instead of inheriting from context.

Alternatives

Emulating the behavior of #[instrument] manually, which is both a lot of code and very error prone.

@jaskij jaskij changed the title tracint_attributes: Add an option to explicitly set parent span in #[instrument] tracing_attributes: Add an option to explicitly set parent span in #[instrument] Mar 24, 2022
@hawkw
Copy link
Member

hawkw commented Mar 31, 2022

Yeah, this seems like a good idea. It should be pretty simple to add. If anyone's interested in working on this, I'm happy to provide guidance.

@hawkw hawkw added kind/feature New feature or request good first issue Good for newcomers crate/attributes Related to the `tracing-attributes` crate labels Mar 31, 2022
@itsyaasir
Copy link

itsyaasir commented Apr 4, 2022

I am interested in working on this , as I am a beginner in contributing to Github OS projects ,and would love to contribute.
Thanks

Yeah, this seems like a good idea. It should be pretty simple to add. If anyone's interested in working on this, I'm happy to provide guidance.

@hawkw
Copy link
Member

hawkw commented Apr 22, 2022

Just realized that this is also a duplicate of #879, so when we close this, we should make sure to close that issue as well.

hawkw pushed a commit that referenced this issue Apr 25, 2022
#2091)

This PR extends the `#[instrument]` attribute to accept an optionally
`parent = …` argument that provides an explicit parent to the generated
`Span`.

## Motivation

This PR resolves #2021 and partially resolves #879. (It only partly
resolves #879 in that it only provides a mechanism for specifying an
explicit parent, but *not* for invoking `follows_from`.)

## Solution

This PR follows the implementation strategy articulated by @hawkw:
#879 (comment).
The user-provided value to the `parent` argument may be any expression,
and this expression is provided directly to the invocation of
[`span!`](https://tracing.rs/tracing/macro.span.html).
hawkw pushed a commit that referenced this issue Apr 26, 2022
#2091)

This PR extends the `#[instrument]` attribute to accept an optionally
`parent = …` argument that provides an explicit parent to the generated
`Span`.

## Motivation

This PR resolves #2021 and partially resolves #879. (It only partly
resolves #879 in that it only provides a mechanism for specifying an
explicit parent, but *not* for invoking `follows_from`.)

## Solution

This PR follows the implementation strategy articulated by @hawkw:
#879 (comment).
The user-provided value to the `parent` argument may be any expression,
and this expression is provided directly to the invocation of
[`span!`](https://tracing.rs/tracing/macro.span.html).
hawkw pushed a commit that referenced this issue Apr 26, 2022
#2091)

This PR extends the `#[instrument]` attribute to accept an optionally
`parent = …` argument that provides an explicit parent to the generated
`Span`.

## Motivation

This PR resolves #2021 and partially resolves #879. (It only partly
resolves #879 in that it only provides a mechanism for specifying an
explicit parent, but *not* for invoking `follows_from`.)

## Solution

This PR follows the implementation strategy articulated by @hawkw:
#879 (comment).
The user-provided value to the `parent` argument may be any expression,
and this expression is provided directly to the invocation of
[`span!`](https://tracing.rs/tracing/macro.span.html).
hawkw pushed a commit that referenced this issue Apr 26, 2022
#2091)

This PR extends the `#[instrument]` attribute to accept an optionally
`parent = …` argument that provides an explicit parent to the generated
`Span`.

## Motivation

This PR resolves #2021 and partially resolves #879. (It only partly
resolves #879 in that it only provides a mechanism for specifying an
explicit parent, but *not* for invoking `follows_from`.)

## Solution

This PR follows the implementation strategy articulated by @hawkw:
#879 (comment).
The user-provided value to the `parent` argument may be any expression,
and this expression is provided directly to the invocation of
[`span!`](https://tracing.rs/tracing/macro.span.html).
hawkw pushed a commit that referenced this issue Apr 26, 2022
#2091)

This PR extends the `#[instrument]` attribute to accept an optionally
`parent = …` argument that provides an explicit parent to the generated
`Span`.

## Motivation

This PR resolves #2021 and partially resolves #879. (It only partly
resolves #879 in that it only provides a mechanism for specifying an
explicit parent, but *not* for invoking `follows_from`.)

## Solution

This PR follows the implementation strategy articulated by @hawkw:
#879 (comment).
The user-provided value to the `parent` argument may be any expression,
and this expression is provided directly to the invocation of
[`span!`](https://tracing.rs/tracing/macro.span.html).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crate/attributes Related to the `tracing-attributes` crate good first issue Good for newcomers kind/feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants