On this page
Sommatic Docs
Open portal

End Trace Span

Closes an active distributed tracing span.

View as Markdown
Open in
Operations Available ops.trace.end Version 1.0.0 Execution: sync

Writes a [TRACE-END] <name> line to the orchestrator log and returns { success: true } on success. It does not look up or close a span and computes no duration.

This operator marks the completion of a specific unit of work (Span). It calculates the duration and finalizing the span status (success/error). It is essential for accurate APM (Application Performance Monitoring) and constructing the full trace waterfall.

Use Cases:

  • Measuring the latency of an external API call block.
  • Grouping a set of complex logic steps into a single readable span.
  • Recording the final status of a custom transaction.

How it works

  1. Merges the input item with the resolved config (config wins).
  2. Leaves through error with Missing 'name' when name is empty. span_id is not checked, although the input contract marks it as required.
  3. Logs [TRACE-END] <name> at info level; trace_id, span_id and attributes passed with it are not written.
  4. Returns { port: "success", success: true }; the engine uses that whole object as the output.

In a workflow

The node as it appears in a workflow file (draft_nodes[]), and the envelope of a successful run.

{
  "node_id": "node-trace-end-checkout",
  "label": "End checkout span",
  "operator_slug": "ops.trace.end",
  "operator_version": "1.0.0",
  "config": {
    "name": "checkout",
    "trace_id": "{{ $json.trace_id }}",
    "span_id": "{{ $json.span_id }}"
  }
}

Configuration

name string Required

Name of the span to close (must match Start Span).

Its configuration shows the shared execution settings, but this node does not apply retries (retryOnFail, maxTries) yet. continueOnFail is not applied by any node.

Behaviour in the code

What the implementation does with these keys beyond what the schema says.

span_id
Not in the config schema (only in the input contract), but read from the node config or, when unset there, from the input item: trace_id, span_id, attributes. None of them is written to the log.

Output ports

success default

name is set.

Data
{
  "port": "success",
  "success": true
}
error

name is empty.

Data
{
  "port": "error",
  "error": "Missing 'name'"
}

In expressions

What a later node can read from this node's output with $("End Trace Span").item.json.<path> (write your node's label instead of End Trace Span). Editor marks the paths the workflow editor suggests under Previous Nodes (the output contract); Worker marks the paths the worker really returns through success, from the output shown in Ports.

ExpressionEditorWorker
$("End Trace Span").item.json.successboolean= true
$("End Trace Span").item.json.duration_msnumberThe worker does not return it: reads as undefined —
$("End Trace Span").item.json.portstringNot suggested by the editor= "success"—

— Editor: The editor suggests it, but the worker does not return it: it reads as undefined.

— Worker: The worker returns it but the editor does not suggest it: write it by hand. Keys inside objects can depend on your data or configuration (for example one key per label).

Errors

Message Port Cause and fix
Missing 'name' error name is set neither on the node nor in the input item.

Input contract

trace_id string Optional

The active Trace ID.

span_id string Required

The Span ID to close.

attributes object Optional

Final tags/attributes (e.g. status code).

Output contract

success boolean Optional
duration_ms number Optional

Contracts (JSON Schema)

The definition exactly as the orchestrator declares it. All is the whole *.definition.js; compare it with the sections above to spot differences between the documentation and the schema. Use it to validate a node before you publish.

{
  "slug": "ops.trace.end",
  "name": "End Trace Span",
  "category": "ops",
  "version": "1.0.0",
  "description": "Closes an active distributed tracing span.\n\n  This operator marks the completion of a specific unit of work (Span). It calculates the duration and finalizing the span status (success/error). It is essential for accurate APM (Application Performance Monitoring) and constructing the full trace waterfall.\n\n  **Use Cases:**\n  - Measuring the latency of an external API call block.\n  - Grouping a set of complex logic steps into a single readable span.\n  - Recording the final status of a custom transaction.",
  "capabilities": [
    "observability",
    "tracing",
    "apm"
  ],
  "config_schema": {
    "type": "object",
    "required": [
      "name"
    ],
    "properties": {
      "name": {
        "type": "string",
        "title": "Span Name",
        "description": "Name of the span to close (must match Start Span)."
      },
      "execution": {
        "type": "object",
        "title": "Execution Settings",
        "properties": {
          "alwaysOutputData": {
            "type": "boolean",
            "title": "Always Output Data",
            "description": "Always output data, even on error (if configured).",
            "default": false
          },
          "retryOnFail": {
            "type": "boolean",
            "title": "Retry On Fail",
            "description": "Retry the execution if it fails.",
            "default": false
          },
          "maxTries": {
            "type": "integer",
            "title": "Max Retries",
            "description": "Number of retries.",
            "default": 3,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "waitBetweenTries": {
            "type": "integer",
            "title": "Wait Between Retries (ms)",
            "default": 1000,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "continueOnFail": {
            "type": "boolean",
            "title": "Continue On Fail",
            "description": "Do not crash workflow on error.",
            "default": false
          },
          "timeout_ms": {
            "type": "integer",
            "title": "Timeout (ms)",
            "description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
            "default": 300000
          }
        }
      }
    }
  },
  "input_contract_schema": {
    "type": "object",
    "properties": {
      "trace_id": {
        "type": "string",
        "description": "The active Trace ID."
      },
      "span_id": {
        "type": "string",
        "description": "The Span ID to close."
      },
      "attributes": {
        "type": "object",
        "description": "Final tags/attributes (e.g. status code)."
      }
    },
    "required": [
      "span_id"
    ]
  },
  "output_contract_schema": {
    "type": "object",
    "description": "Confirmation.",
    "properties": {
      "success": {
        "type": "boolean"
      },
      "duration_ms": {
        "type": "number"
      }
    }
  },
  "ports": [
    {
      "port_id": "success",
      "label": "Ended",
      "is_default": true,
      "description": "Span closed successfully."
    },
    {
      "port_id": "error",
      "label": "Error",
      "description": "Failed to find or close span."
    }
  ],
  "execution_mode": "sync",
  "tags": [
    "observability",
    "tracing",
    "telemetry"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_vectry",
    "profile": {
      "name": "Vectry Analytics",
      "verified": true,
      "url": "https://me.veripass.com/vectry",
      "logo_url": null
    }
  }
}

Execution

Execution
sync
Stateful
No
Retries (retryOnFail)
No
Capabilities
observabilitytracingapm
Tags
observabilitytracingtelemetry

Notes and limits

  • duration_ms appears in the output contract but is never returned.
  • The runtime logger prints only the message text: the structured object passed with it is not written to the log.
  • The worker returns its fields at the top level instead of under data, so the engine uses the whole returned object, port included, as the node output.
  • Leaving through error does not fail the run: the engine follows the edges wired to error, and if there are none the branch simply ends.
  • The execution settings (retryOnFail, maxTries, waitBetweenTries, continueOnFail, timeout_ms) are accepted, but neither this worker nor the engine applies them.

Reviewed against the orchestrator code · 31e874b · 2026-11-26

Install agent tools

Give your coding agent the official Sommatic AI docs: skills, the docs MCP server and Markdown pages, so it never has to scrape the site.

Skills only. They do not update by themselves; run it again to refresh.

npx skills add https://docs.sommatic.ai
How agents read these docs