Skip to content

[Feature Request] Add OTEL tracing information as attribute on log messages emitted using Workflow Logger #1425

Description

@lucaskatayama

What are you really trying to do?

Get OpenTelemetry trace_id and span_id fields on Workflow logs.

Describe the bug

The tracing fields from OpenTelemetry (trace_id and span_id) is not appearing on Workflow logs specifically.

It works on Client and Activities.

Calling worflow.log.error:

{"label":"workflow","level":"error","message":"hello","namespace":"default","runId":"add5d842-ca36-4fee-8e51-624d7b2bb58c","sdkComponent":"workflow","taskQueue":"interceptors-opentelemetry-example","timestamp":1716328238734,"workflowId":"otel-example-0","workflowType":"example"}

Calling activity.log.error

{"activityId":"1","activityType":"greet","attempt":1,"isLocal":false,"label":"activity","level":"error","message":"alskjdbnkajsdbnkjandsjk","namespace":"default","sdkComponent":"activity","span_id":"10036d093b04a315","taskQueue":"interceptors-opentelemetry-example","taskToken":"CiRjYmI4ODI1My0wOWMyLTRiMzMtOWI3YS05MTQ5ODFhMzdjM2USDm90ZWwtZXhhbXBsZS0wGiRhZGQ1ZDg0Mi1jYTM2LTRmZWUtOGU1MS02MjRkN2IyYmI1OGMgBSgBMgExQgVncmVldEoICAEQxo5AGAE=","timestamp":1716328238737,"trace_flags":"01","trace_id":"f2731bb716c062624923e55b29f8fcec","workflowId":"otel-example-0","workflowRunId":"add5d842-ca36-4fee-8e51-624d7b2bb58c","workflowType":"example"}

Which gives "span_id":"10036d093b04a315" and "trace_id":"f2731bb716c062624923e55b29f8fcec".

Minimal Reproduction

  1. From interceptors-opentelemetry sample: https://github.com/temporalio/samples-typescript/tree/main/interceptors-opentelemetry
  2. Enable OpenTelemetry Auto Instrumentation for JS for winston (https://opentelemetry.io/docs/languages/js/automatic/)
export OTEL_NODE_RESOURCE_DETECTORS="env,host,os,serviceinstance"
export OTEL_SERVICE_NAME="client"
export NODE_OPTIONS="--require @opentelemetry/auto-instrumentations-node/register"
export OTEL_NODE_ENABLED_INSTRUMENTATIONS="winston,http"
  1. Enable custom-logger using https://github.com/temporalio/samples-typescript/tree/main/custom-logger
  2. Log on Workflow
import * as workflow from "@temporalio/workflow"

// A workflow that simply calls an activity
export async function example(name: string): Promise<string> {
  workflow.log.error("hello");
  return await greet(name);
}
  1. Log on Activity
import * as activity from "@temporalio/activity"

export async function greet(name: string): Promise<string> {
  activity.log.error("alskjdbnkajsdbnkjandsjk")
  return `Hello, ${name}!`;
}
  1. Call client to execute workflow (npm run workflow)

Environment/Versions

  • OS and processor: M2 Mac
  • Temporal Version:
❯ temporal --version
temporal version 0.12.0 (server 1.23.0) (ui 2.26.2)
  • Are you using Docker or Kubernetes or building Temporal from source? No

Additional context

  • The trace_id and span_id are generated but they doesn't appear on logs and are being reported to newrelic correctly, because they appear on distributed tracing.

From ConsoleSpanExporter

{
  resource: { attributes: { 'service.name': 'interceptors-sample-worker' } },
  traceId: 'd498bbf00762a58fc78c022804644789', <<<<<<<<<<
  parentId: '38b7d260146c73e6', <<<<<<<<
  traceState: undefined,
  name: 'RunWorkflow:example',
  id: 'aaa81665fd7d1198',
  kind: 0,
  timestamp: 1716328235467000,
  duration: 46000,
  attributes: {
...
{
  resource: { attributes: { 'service.name': 'interceptors-sample-worker' } },
  traceId: 'd498bbf00762a58fc78c022804644789',
  parentId: 'aaa81665fd7d1198',
  traceState: undefined,
  name: 'StartActivity:greet',
  id: 'aec76af986522d29',
  kind: 0,

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions