Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(provisioner): propagate trace info#17166

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
spikecurtis merged 4 commits intocoder:mainfromcoryb:trace-provider
Apr 8, 2025

Conversation

coryb
Copy link
Contributor

If tracing is enabled, propagate the trace information to the terraform provisioner via environment variables. This sets theTRACEPARENT environment variable using the default W3C trace propagators. Users can choose to continue the trace by adding new spans in the provisioner by reading from the environment like:

ctx := env.ContextWithRemoteSpanContext(context.Background(), os.Environ())

@cdr-botcdr-botbot added the communityPull Requests and issues created by the community. labelMar 29, 2025
@corybcoryb changed the titlefeat(coderd): propagate trace info to provisionerfeat(provisioner): propagate trace infoMar 29, 2025
@corybcoryb marked this pull request as ready for reviewMarch 29, 2025 21:34
@spikecurtis
Copy link
Contributor

Thanks for the PR!

Can you say a little more about the use case for this change? It appears thatterraform itselfdoesn't yet process TRACEPARENT. Are there provisioners you use that do process it?

@coryb
Copy link
ContributorAuthor

Can you say a little more about the use case for this change? It appears that terraform itselfhashicorp/terraform#35444. Are there provisioners you use that do process it?

Correct, terraform itself won't use it, but it will maintain it in the environment for the provider binaries it calls. We (Netflix) have a custom provider to implement our deployment strategies and would like the ability to continue traces that were started in Coder or further upstream. For example, our provider Create and Update methods will just call:

ctx := env.ContextWithRemoteSpanContext(context.Background(), os.Environ())

Then any new spans created will use the inherited span context.

The primary use case is to enhance our integration testing. In our tests, we start a trace and can see the spans between our test into Coder where it invokes terraform. Currently, in our terraform provider we have to start a new trace, where we collect spans through to workspace startup. With this patch, we will be able to connect our traces from the test entirely through to workspace startup, which should help with visibility/debugging.

@spikecurtis
Copy link
Contributor

That makes sense!

I have to say, from a supply-chain security standpoint, we are very reluctant to add a dependency ongithub.com/coryb/otelbundle if we can avoid it. If you're OK with it, we'd be willing to accept thepropagation/env implementation as a contribution directly to this repo.

The other thing I'd ask for is a unit test of the propagation.

@coryb
Copy link
ContributorAuthor

I have to say, from a supply-chain security standpoint, we are very reluctant to add a dependency on github.com/coryb/otelbundle if we can avoid it. If you're OK with it, we'd be willing to accept the propagation/env implementation as a contribution directly to this repo.

Thanks, works for me, I will update. You should be able to swap out the implementation with an official OTEL support once they get that sorted.

@corybcorybforce-pushed thetrace-provider branch 2 times, most recently from1b211bd to4459db5CompareApril 4, 2025 17:21
@coryb
Copy link
ContributorAuthor

@spikecurtis copied the required code to inject the trace env, and made all the functions unexported. Also added a test to ensure the TRACEPARENT env var is set/updated.

@coryb
Copy link
ContributorAuthor

updated for lint rules...

If tracing is enabled, propagate the trace information to the terraformprovisioner via environment variables.  This sets the `TRACEPARENT`environment variable using the default W3C trace propagators.  Userscan choose to continue the trace by adding new spans in the provisionerby reading from the environment like:ctx := env.ContextWithRemoteSpanContext(context.Background(), os.Environ())
Copy link
Contributor

@spikecurtisspikecurtis left a comment

Choose a reason for hiding this comment

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

Few nits inline, but I think this is very close.

// don't directly update the slice so we don't modify the slice
// passed in
newEnv := slices.Clone(c.Env)
newEnv = append(newEnv[:i], append([]string{fmt.Sprintf("%s=%s", key, value)}, newEnv[i+1:]...)...)
Copy link
Contributor

Choose a reason for hiding this comment

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

Once you've cloned the initial slice, seems like it would be simpler to just modify in place, rather than re-slice and append.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

hah, I think that code went through too many refactors and came out nonsense. I have simplified it.

)

// TODO: replace this with the upstream OTEL env propagation when it is
// released.
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -0,0 +1,63 @@
package terraform // nolint:testpackage
Copy link
Contributor

Choose a reason for hiding this comment

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

file should be namedotelenv_internal_test.go then you don't need thisnolint

coryb reacted with thumbs up emoji
coryband others added3 commitsApril 7, 2025 07:49
Co-authored-by: Spike Curtis <spike@spikecurtis.com>
Co-authored-by: Spike Curtis <spike@spikecurtis.com>
Simplified the slice copy/update logic.  Removed the panics for nonrequired interface functions, the impl was trivial, added simple teststo ensure they work as expected.
@spikecurtisspikecurtis merged commit12e5718 intocoder:mainApr 8, 2025
29 checks passed
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsApr 8, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@spikecurtisspikecurtisspikecurtis approved these changes

Assignees

@corybcoryb

Labels
communityPull Requests and issues created by the community.
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@coryb@spikecurtis

[8]ページ先頭

©2009-2025 Movatter.jp