Skip to content

Commit a5b5b9f

Browse files
authored
Include task payload in OTEL debug (temporalio#7174)
## What changed? <!-- Describe what has changed in this PR --> Include the task data in the OTEL span when OTEL debug is enabled. ## Why? <!-- Tell your future self why have you made these changes --> Help with debugging/learning the system. ## How did you test it? <!-- How have you verified this change? Tested locally? Added a unit test? Checked in staging env? --> Checked in Grafana. Example: ``` "payload": { "NamespaceID": "a9aac188-6188-41f0-b7de-16ef62cb7193", "RunID": "0194af8c-df6d-7829-9c35-a88cc288da89", "ScheduledEventID": 2, "TaskID": 1048633, "TaskQueue": "TestUpdateWorkflowSuite/TestUpdateWorkflow_CompleteWorkflow_AbortUpdates/update_admitted_workflow_completed_task_queue", "Version": 0, "VisibilityTimestamp": "2025-01-29T00:53:52.621907Z", "WorkflowID": "TestUpdateWorkflowSuite/TestUpdateWorkflow_CompleteWorkflow_AbortUpdates/update_admitted_workflow_completed_workflow_id" } ``` ## Potential risks <!-- Assuming the worst case, what can be broken when deploying this change to production? --> Only enabled in debug mode. ## Documentation <!-- Have you made sure this change doesn't falsify anything currently stated in `docs/`? If significant new behavior is added, have you described that in `docs/`? --> ## Is hotfix candidate? <!-- Is this PR a hotfix candidate or does it require a notification to be sent to the broader community? (Yes/No) -->
1 parent b01f22f commit a5b5b9f

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

service/history/queues/executable.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ package queues
2828

2929
import (
3030
"context"
31+
"encoding/json"
3132
"errors"
3233
"fmt"
3334
"math"
@@ -283,7 +284,7 @@ func (e *executableImpl) Execute() (retErr error) {
283284
)
284285
e.Unlock()
285286

286-
// Wrapped in if block to avoid unnecessary allocations when OTEL is disables.
287+
// Wrapped in if block to avoid unnecessary allocations when OTEL is disabled.
287288
if telemetry.IsEnabled(e.tracer) {
288289
var span trace.Span
289290
ctx, span = e.tracer.Start(
@@ -293,8 +294,17 @@ func (e *executableImpl) Execute() (retErr error) {
293294
trace.WithAttributes(
294295
attribute.Key(telemetry.WorkflowIDKey).String(e.GetWorkflowID()),
295296
attribute.Key(telemetry.WorkflowRunIDKey).String(e.GetRunID()),
296-
attribute.Key("task.type").String(e.GetType().String()),
297-
attribute.Key("task.id").Int64(e.GetTaskID())))
297+
attribute.Key("queue.task.type").String(e.GetType().String()),
298+
attribute.Key("queue.task.id").Int64(e.GetTaskID())))
299+
300+
if telemetry.DebugMode() {
301+
if taskPayload, err := json.Marshal(e.GetTask()); err != nil {
302+
e.logger.Error("failed to serialize task payload for OTEL span", tag.Error(err))
303+
} else {
304+
span.SetAttributes(attribute.Key("queue.task.payload").String(string(taskPayload)))
305+
}
306+
}
307+
298308
defer func() {
299309
if retErr != nil {
300310
span.RecordError(retErr)

0 commit comments

Comments
 (0)