Use variables in Workflow Links

When you create Workflow Links, you use variables in the Name and URL so that span-specific content displays. Variables use the Mustache syntax.

For example, in this link definition:

Name Playbook for {{$service}} - {{MY_ERROR_TYPE_ATTRIBUTE}} error
URL http://wiki.com/playbook-{{$service}}-{{MY_ERROR_TYPE_ATTRIBUTE}}
Rules
{
  "$service": null,
  "$hasError": [true],
  "MY_ERROR_TYPE_ATTRIBUTE": null
}
      

Both {{$service}} and {{MY_ERROR_TYPE_ATTRIBUTE}} are variables. The {{$service}} variable resolves to the span’s service and is a Cloud Observability variable (denoted by the $). The {{MY_ERROR_TYPE_ATTRIBUTE}} represents a user-defined variable. User-defined variables don’t use the $. Here, it represents an attribute on a span. Any attribute you have on your spans can be used as a variable.

User-defined variables

The attributes that you create in your tracing code can be used as variables in Workflow Links. For example, if you’ve created the error_type attribute in your code like this:

1
2
3
4
5
6
Span span = tracer.spanBuilder("/project/:project-id/list") // operation named after the route
                 .setSpanKind(Span.Kind.CLIENT) // tag the span as a service boundary
                 .startSpan();

  span.setAttribute("error_type_", "world");
  span.end()

Then you can use the {{error_type}} variable in your links. However, you need to be sure that the attribute exists for the span. The easiest way to do this is to view the sidebar on the Trace View page. Attributes are listed for the span there.

Cloud Observability variables

The following are the Cloud Observability-specific variables that you can use in your Workflow Link names, URLs, and rules. Many of these also appear in the sidebar of the Trace View page.

Be sure to use a $ in front of all Cloud Observability variables.

Span variables

These variables provide information about a span.

Variable Definition
$hasError The span has the attribute error=true
$operation The name of the span’s operation
$parentSpanGUID The ID of this span’s parent
$service The name of the span’s service
$spanGUID The span’s ID
$traceGUID The ID of the trace that this span belongs to

Time-based variables

These variables provide time information about the span.

Variable Definition
$durationMicros The duration of this span, in microseconds
$endTimeISO The span's end time, expressed in UTC (ISO 8601 format), e.g. 2019-06-18T00:17:59.131Z
$endTimeMicros The span's end time, rounded to microseconds
$endTimeMillis The span's end time, rounded to milliseconds
$endTimeMillis-5min Five minutes before the span's end time in milliseconds
$endTimeMillis+5min Five minutes after the span's end time in milliseconds
$endTimeMillis-1hr One hour before the span's end time in milliseconds
$endTimeMillis+1hr One hour after the span's end time in milliseconds
$startTimeISO The span's start time, expressed in UTC (ISO 8601 format), e.g. 2019-06-18T00:17:59.131Z
$startTimeISO-5min Five minutes before the span start time, expressed in UTC (ISO 8601 format), e.g. 2019-06-18T00:17:59.131Z
$startTimeISO+5mi The span's start time, plus five minutes, expressed in UTC (ISO 8601 format), e.g. 2019-06-18T00:17:59.131Z
$startTimeISO-1hr One hour before the span start time, expressed in UTC (ISO 8601 format), e.g. 2019-06-18T00:17:59.131Z
$startTimeISO+1hr The span's start time, plus one hour, expressed in UTC (ISO 8601 format), e.g. 2019-06-18T00:17:59.131Z
$startTimeMicros The span's start time, rounded to microseconds
$startTimeMillis The span's start time, rounded to milliseconds
$startTimeMillis-5min Five minutes before the span's start time, rounded to milliseconds
$startTimeMillis+5min The span's start time, plus five mintues, rounded to milliseconds
$startTimeMillis-1hr One hour before the span's start time, rounded to milliseconds
$startTimeMillis+1hr The span's start time, plus one hour, in milliseconds, (rounded down)
$startTimeSeconds-5min Five minutes before the span start time, rounded to seconds
$startTimeSeconds+5min The span's start time, plus five minutes, rounded to seconds
$startTimeSeconds-1hr One hour before the span start time, rounded to seconds
$startTimeSeconds+1hr The span's start time, plus one hour, rounded to seconds

Miscellaneous variables

Variable Definition
$platform The type of client library that reported this span, for example, java, go, python
$platformVersion The version of the client library that reported this span, e.g. go1.12.5
$project Name of the Cloud Observability project that includes this span (as shown in the page URL)

See also

Create and manage Workflow Links

Workflow Links cookbook

Updated Dec 1, 2019