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

add traceparent header support #81

Merged
merged 2 commits into from
Dec 1, 2023
Merged

add traceparent header support #81

merged 2 commits into from
Dec 1, 2023

Conversation

vikramraman
Copy link
Contributor

When leveraging the provider via code (tf-exec) it's useful to pass along the trace context.

This change adds support for setting the W3C traceparent header via an optional provider level property.

Copy link
Contributor

@bendrucker bendrucker left a comment

Choose a reason for hiding this comment

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

Nice! Code looks fine, just some minor RFC-adherence nits and questions about usage.

FWIW, I think there's a reasonable case to be made for omitting these types of internals (managed_by_id too) from the provider config and only accepting inputs as environment variables. That essentially makes them "secret" (as in undocumented, not sensitive) configuration inputs. I can't imagine users wanting to set this from their own environments. And so it just creates clutter in the schema/docs.

@@ -110,6 +110,12 @@ func Provider() *schema.Provider {
Optional: true,
Description: "ID of an Observe object that serves as the parent (managing) object for all resources created by the provider (internal use).",
},
"traceparent": {
Type: schema.TypeString,
DefaultFunc: schema.EnvDefaultFunc("W3C_TRACEPARENT", nil),
Copy link
Contributor

@bendrucker bendrucker Nov 30, 2023

Choose a reason for hiding this comment

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

Suggested change
DefaultFunc: schema.EnvDefaultFunc("W3C_TRACEPARENT", nil),
DefaultFunc: schema.EnvDefaultFunc("TRACEPARENT", nil),

I'm unable to find any cases where this is used as a configuration input (versus just internally to the code):

https://github.com/search?q=%22W3C_TRACEPARENT%22&type=code&p=1

I did find this:

open-telemetry/opentelemetry-specification#740 (comment)

Type: schema.TypeString,
DefaultFunc: schema.EnvDefaultFunc("W3C_TRACEPARENT", nil),
Optional: true,
Description: "Optional traceparent identifie.",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Description: "Optional traceparent identifie.",
Description: "A trace identifier to attach to all HTTP requests in the traceparent header (https://www.w3.org/TR/trace-context/#traceparent-header)",

@@ -110,6 +110,12 @@ func Provider() *schema.Provider {
Optional: true,
Description: "ID of an Observe object that serves as the parent (managing) object for all resources created by the provider (internal use).",
},
"traceparent": {
Copy link
Contributor

Choose a reason for hiding this comment

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

Wondering whether it's worth adding validation to this field, since traceparent is not just an opaque ID and instead has multiple well-structured parts:

https://www.w3.org/TR/trace-context/#traceparent-header-field-values

The RFC says multiple times that "vendors MUST ignore" the traceparent if any of the fields are invalid.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thought about this, and leaned against adding validation. Mainly as we are just passing the context through to the server. And the extract logic on the server does validate and ignore if the fields are invalid (essentially starts a new trace).

Copy link
Contributor

Choose a reason for hiding this comment

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

If it's exposed to users I tend to think more validation is better if it can turn a silent failure into an explicit error. By not officially exposing the option to users that safety/predictability imperative largely goes away. So 👍🏻 to no validation in combo with the move to env only.

@bendrucker
Copy link
Contributor

Oh and re provider config fields vs env only, if you do keep the explicit field, you'll need to go generate ./... to render that into the docs.

@vikramraman
Copy link
Contributor Author

Moved traceparent to just an envvar. Did not port the managed_by_id as part of this change as that has a broader surface area to test. I will look into that separately.

Copy link
Contributor

@bendrucker bendrucker left a comment

Choose a reason for hiding this comment

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

Did not port the managed_by_id as part of this change as that has a broader surface area

And a breaking change regardless so definitely for separate consideration/release

@vikramraman vikramraman merged commit cbdc04a into master Dec 1, 2023
5 checks passed
@vikramraman vikramraman deleted the vikramr/traceparent branch December 1, 2023 23:10
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.

2 participants