[OTel] Add resource type trace attribute to all resource instance spans

Signed-off-by: James Humphries <james@james-humphries.co.uk>
This commit is contained in:
James Humphries
2026-02-12 15:59:45 +00:00
parent 8da8e5e216
commit c488bfbb48
7 changed files with 14 additions and 3 deletions

View File

@@ -53,6 +53,14 @@ const traceNameApplyResourceInstance = "Apply resource instance changes"
// 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
@@ -2822,7 +2830,6 @@ func (n *NodeAbstractResourceInstance) apply(
keyData instances.RepetitionData,
createBeforeDestroy bool,
) (*states.ResourceInstanceObject, tfdiags.Diagnostics) {
var diags tfdiags.Diagnostics
if state == nil {
state = &states.ResourceInstanceObject{}
@@ -3389,7 +3396,6 @@ func (n *NodeAbstractResourceInstance) deferEphemeralResource(evalCtx EvalContex
plannedNewState *states.ResourceInstanceObject,
diags tfdiags.Diagnostics,
) {
unmarkedConfigVal, configMarkPaths := configVal.UnmarkDeepWithPaths()
proposedNewVal := objchange.PlannedUnknownObject(schema, unmarkedConfigVal)
proposedNewVal = proposedNewVal.MarkWithPaths(configMarkPaths)

View File

@@ -126,6 +126,7 @@ func (n *NodeApplyableResourceInstance) Execute(ctx context.Context, evalCtx Eva
ctx, traceNameApplyResourceInstance,
tracing.SpanAttributes(
traceattrs.String(traceAttrResourceInstanceAddr, addr.String()),
traceattrs.String(traceAttrResourceType, addr.Resource.Resource.Type),
),
)
defer span.End()
@@ -447,7 +448,6 @@ func (n *NodeApplyableResourceInstance) managedResourceExecute(ctx context.Conte
}
func (n *NodeApplyableResourceInstance) managedResourcePostconditions(ctx context.Context, evalCtx EvalContext, repeatData instances.RepetitionData) (diags tfdiags.Diagnostics) {
checkDiags := evalCheckRules(
ctx,
addrs.ResourcePostcondition,

View File

@@ -97,6 +97,7 @@ func (n *NodePlanDeposedResourceInstanceObject) Execute(ctx context.Context, eva
ctx, traceNamePlanResourceInstance,
tracing.SpanAttributes(
traceattrs.String(traceAttrResourceInstanceAddr, n.Addr.String()),
traceattrs.String(traceAttrResourceType, n.Addr.Resource.Resource.Type),
traceattrs.Bool(traceAttrPlanRefresh, !n.skipRefresh),
),
)

View File

@@ -157,6 +157,7 @@ func (n *NodeDestroyResourceInstance) Execute(ctx context.Context, evalCtx EvalC
ctx, traceNameApplyResourceInstance,
tracing.SpanAttributes(
traceattrs.String(traceAttrResourceInstanceAddr, addr.String()),
traceattrs.String(traceAttrResourceType, addr.Resource.Resource.Type),
),
)
defer span.End()

View File

@@ -63,6 +63,7 @@ func (n *NodePlanDestroyableResourceInstance) Execute(ctx context.Context, evalC
ctx, traceNamePlanResourceInstance,
tracing.SpanAttributes(
traceattrs.String(traceAttrResourceInstanceAddr, addr.String()),
traceattrs.String(traceAttrResourceType, addr.Resource.Resource.Type),
traceattrs.Bool(traceAttrPlanRefresh, !n.skipRefresh),
),
)

View File

@@ -94,6 +94,7 @@ func (n *NodePlannableResourceInstance) Execute(ctx context.Context, evalCtx Eva
ctx, traceNamePlanResourceInstance,
tracing.SpanAttributes(
traceattrs.String(traceAttrResourceInstanceAddr, addr.String()),
traceattrs.String(traceAttrResourceType, addr.Resource.Resource.Type),
traceattrs.Bool(traceAttrPlanRefresh, !n.skipRefresh),
traceattrs.Bool(traceAttrPlanPlanChanges, !n.skipPlanChanges),
),

View File

@@ -64,6 +64,7 @@ func (n *NodePlannableResourceInstanceOrphan) Execute(ctx context.Context, evalC
ctx, traceNamePlanResourceInstance,
tracing.SpanAttributes(
traceattrs.String(traceAttrResourceInstanceAddr, addr.String()),
traceattrs.String(traceAttrResourceType, addr.Resource.Resource.Type),
traceattrs.Bool(traceAttrPlanRefresh, !n.skipRefresh),
traceattrs.Bool(traceAttrPlanPlanChanges, !n.skipPlanChanges),
),