OpenTelemetry support for Terraform

Hi folks,

I wonder if you plan adding OpenTelemetry support to Terraform.

It would be really helpful to see where Terraform spends time on, especially at a scale with many resources.

I see there’s an OpenTelemetry support in the Cloud Agent but the only reference in Terraform is an otlp proto Go module.

Hi @scadu,

We have in the past investigated this possibility and found that it seems technically possible in principle and could be useful to do so but because of Terraform’s age as a codebase (it predates not only OpenTelemetry but also the context.Context convention for passing around telemetry context) it would require some cross-cutting internal API changes first, and so far we’ve not been able to prioritize that over development of other capabilities that are in higher demand.

In the meantime it is possible in principle to extract some shallow telemetry-like information by running Terraform in its JSON output mode: terraform plan -json and terraform apply -json. This of course doesn’t integrate directly with OpenTelemetry tools and protocols, and it only announces the top-level resource lifecycle events that Terraform Core orchestrates, but I mention it because in the past folks have used it for answering profiling-like questions, such as “which resources are taking the longest in this long-running plan operation?”.

Appreciate quick response and additional information regarding the implementation. Would be nice to see OpenTelemetry support at some point, though I understand it’s not as fast to implement as with a fresh codebase.

Using terraform plan -json to see how long it takes to apply changes to given resources is fine, but it becomes tricky to pinpoint a problem when I’m trying to detect some expensive lookups and other operations that are not tied to the resource directly. And that’s when tracing would be really useful.

1 Like