Repository: opentofu/opentofu
File: internal/tofu/node_resource_abstract_instance.go (Go)

Code before:

// traceNamePlanResourceInstance is a standardize trace span name we use for the
// overall execution of all graph nodes that somehow represent the planning
// phase for a resource instance.
const traceNamePlanResourceInstance = "Plan resource instance changes"

// traceNameApplyResourceInstance is a standardize trace span name we use for
// the overall execution of all graph nodes that somehow represent the apply
// phase for a resource instance.
const traceNameApplyResourceInstance = "Apply resource instance changes"

// traceAttrResourceInstanceAddr is a standardized trace span attribute
// name that we use for recording the address of the main resource instance that
// a particular span is concerned with.
//
// The value of this should be populated by calling the String method on
// a value of type [addrs.AbsResourceInstance].
const traceAttrResourceInstanceAddr = "opentofu.resource_instance.address"

// traceAttrResourceType is a standardized trace span attribute name that we
// use for recording the type of the resource that a particular span is
// concerned with, such as "aws_instance" or "google_compute_disk".
//
// The value of this should be populated from the Type field of the
// [addrs.Resource] embedded in the relevant [addrs.AbsResourceInstance].
const traceAttrResourceType = "opentofu.resource_instance.type"

// traceAttrPlanRefresh is a standardized trace span attribute name that we use
// for a boolean attribute describing whether the refresh step is enabled
// for the main resource instance associated with the span during the planning
// phase.
const traceAttrPlanRefresh = "opentofu.plan.refresh"

// traceAttrPlanPlanChanges is a standardized trace span attribute name that we
// use for a boolean attribute describing whether the plan step is enabled
// for the main resource instance associated with the span during the planning
// phase. (This is false in refresh-only mode.)
const traceAttrPlanPlanChanges = "opentofu.plan.plan_changes"

// NodeAbstractResourceInstance represents a resource instance with no
// associated operations. It embeds NodeAbstractResource but additionally
// contains an instance key, used to identify one of potentially many
// instances that were created from a resource in configuration, e.g. using
// the "count" or "for_each" arguments.
type NodeAbstractResourceInstance struct {
	NodeAbstractResource
	Addr addrs.AbsResourceInstance

	// These are set via the AttachState method.
	instanceState *states.ResourceInstance


Review comment (bug):
I guess you were going for consistency with the prefix of `opentofu.resource_instance.address` above, and I think that is a reasonable thing to aim for.

I would probably have chosen just `opentofu.resource.type` here because "type" is property of the resource rather than of the instances of a resource (all instances of a resource must always have the same type), but I also don't think this matters a great deal so I'm just mentioning it to see what you think, rather than trying to convince you to change it.

(Perhaps one specific argument in favor of changing it is that we might use this same attribute on other trace spans that are talking about something we're doing for resources _as a whole_, such as calculating their "dynamic expansion", and in that case using resource instance _would_ be more clearly "wrong". But for what you used it for in this commit that argument doesn't apply.)


Code after:

// traceNamePlanResourceInstance is a standardize trace span name we use for the
// overall execution of all graph nodes that somehow represent the planning
// phase for a resource instance.
const traceNamePlanResourceInstance = "Plan resource instance changes"

// traceNameApplyResourceInstance is a standardize trace span name we use for
// the overall execution of all graph nodes that somehow represent the apply
// phase for a resource instance.
const traceNameApplyResourceInstance = "Apply resource instance changes"

// traceAttrResourceInstanceAddr is a standardized trace span attribute
// name that we use for recording the address of the main resource instance that
// a particular span is concerned with.
//
// The value of this should be populated by calling the String method on
// a value of type [addrs.AbsResourceInstance].
const traceAttrResourceInstanceAddr = "opentofu.resource_instance.address"

// traceAttrResourceType is a standardized trace span attribute name that we
// use for recording the type of the resource that a particular span is
// concerned with, such as "aws_instance" or "google_compute_disk".
//
// The value of this should be populated from the Type field of the
// [addrs.Resource] embedded in the relevant [addrs.AbsResourceInstance].
const traceAttrResourceType = "opentofu.resource.type"

// traceAttrPlanRefresh is a standardized trace span attribute name that we use
// for a boolean attribute describing whether the refresh step is enabled
// for the main resource instance associated with the span during the planning
// phase.
const traceAttrPlanRefresh = "opentofu.plan.refresh"

// traceAttrPlanPlanChanges is a standardized trace span attribute name that we
// use for a boolean attribute describing whether the plan step is enabled
// for the main resource instance associated with the span during the planning
// phase. (This is false in refresh-only mode.)
const traceAttrPlanPlanChanges = "opentofu.plan.plan_changes"

// NodeAbstractResourceInstance represents a resource instance with no
// associated operations. It embeds NodeAbstractResource but additionally
// contains an instance key, used to identify one of potentially many
// instances that were created from a resource in configuration, e.g. using
// the "count" or "for_each" arguments.
type NodeAbstractResourceInstance struct {
	NodeAbstractResource
	Addr addrs.AbsResourceInstance

	// These are set via the AttachState method.
	instanceState *states.ResourceInstance