Commit Graph

12 Commits

Author SHA1 Message Date
Martin Atkins
93d095c67e traceattrs: Functions for the commonly-used OCI-related attributes
We have a number of trace attributes that we use across all of our OCI
Distribution-based functionality, so this centralizes their definitions
in package traceattrs.

This intentionally ignores a few additional attribute names that are used
only in the code that interacts with Docker-style credential helpers,
because all of those are used only in a single function and so adding
indirection for those doesn't have enough benefit to offset the cost of
additional indirection.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-11-03 11:41:50 -08:00
Martin Atkins
35cd016693 tracing: Re-export semconv.OCIManifestDigest
We previously added re-exports for some of the functions we'd previously
been importing directly from semconv elsewhere in this codebase. For this
one we'd previously just hard-coded the standardized attribute name, but
for consistency we'll also use a re-export of a semconv function for this
one too.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-11-03 11:41:50 -08:00
Martin Atkins
0503163e28 tracing: Centralize our OpenTelemetry package imports
OpenTelemetry has various Go packages split across several Go modules that
often need to be carefully upgraded together. And in particular, we are
using the "semconv" package in conjunction with the OpenTelemetry SDK's
"resource" package in a way that requires that they both agree on which
version of the OpenTelemetry Semantic Conventions are being followed.

To help avoid "dependency hell" situations when upgrading, this centralizes
all of our direct calls into the OpenTelemetry SDK and tracing API into
packages under internal/tracing, by exposing a few thin wrapper functions
that other packages can use to access the same functionality indirectly.

We only use a relatively small subset of the OpenTelemetry library surface
area, so we don't need too many of these reexports and they should not
represent a significant additional maintenance burden.

For the semconv and resource interaction in particular this also factors
that out into a separate helper function with a unit test, so we should
notice quickly whenever they become misaligned. This complements the
end-to-end test previously added in opentofu/opentofu#3447 to give us
faster feedback about this particular problem, while the end-to-end test
has the broader scope of making sure there aren't any errors at all when
initializing OpenTelemetry tracing.

Finally, this also replaces the constants we previously had in package
traceaddrs with functions that return attribute.KeyValue values directly.
This matches the API style used by the OpenTelemetry semconv packages, and
makes the calls to these helpers from elsewhere in the system a little
more concise.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-10-30 13:27:10 -07:00
Christian Mesh
58b722c423 Fix OTEL init from semconv conflict (#3446)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-10-29 15:17:20 -04:00
Martin Atkins
c7afcdf9b4 tracing: Don't panic on OpenTelemetry errors (#3235)
Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-09-03 07:37:45 -04:00
Martin Atkins
324ef91c4e tofu: Test that context.Context values can reach the provider calls
This introduces a new testing helper to package tracing which we can use
to make sure that context.Context values are able to reach all the way
from a test caller to some specific function elsewhere in the system.

We then use that helper in package tofu to test whether context values are
able to reach calls to providers, which tend to be the deepest place that
package tofu is responsible for routing them to.

As of this test the providers.Interface.Configure method does not seem to
receive values, so that is currently commented out in this test and we'll
deal with that properly in a subsequent commit.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-06-13 08:21:32 -07:00
James Humphries
a9751ee2b6 Allow end-users to set OTEL_SERVICE_NAME (#2841)
Signed-off-by: James Humphries <james@james-humphries.co.uk>
2025-05-23 11:07:45 +01:00
James Humphries
19afe5ffbb Consume TRACEPARENT and TRACESTATE to construct the OTel trace context (#2763)
Signed-off-by: James Humphries <james@james-humphries.co.uk>
2025-05-07 16:20:11 +01:00
Martin Atkins
69bdc51303 tracing: StringSlice utility
Most OpenTofu executions will not have tracing enabled, so it's important
that we don't waste time calculating data for trace attributes that will
immediately get discarded without being recorded.

This commit establishes the first of possibly multiple utilities that
take a span and then compute a result only if that span is actually going
to be recorded somewhere.

This first one is intended for populating StringSlice attributes from
collections of objects that implement fmt.Stringer. Both the conversion
to string and the construction of the final slice are likely to cause
memory allocation, so we'd rather not do any of that work unless trace
collection is actually enabled.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-05-07 08:12:13 -07:00
James Humphries
6d3aed0e8f [OpenTelemetry] Add module init tracing (#2711)
Signed-off-by: James Humphries <james@james-humphries.co.uk>
2025-05-01 14:15:03 +01:00
James Humphries
8629b0a49a [OpenTelemetry] Add traces to providers lock command (#2694)
Signed-off-by: James Humphries <james@james-humphries.co.uk>
2025-04-28 17:01:38 +01:00
James Humphries
d92d4f9c11 [OpenTelemetry] Add traces to init command (#2665)
Signed-off-by: James Humphries <james@james-humphries.co.uk>
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
Co-authored-by: Christian Mesh <christianmesh1@gmail.com>
2025-04-25 12:40:48 +01:00