Skip to content

patch-console.ts preserves json formatted logs as json format. #628

Open
@abroom

Description

@abroom

Expected Behavior

patch-console.ts adds dd key and value to the log if it is json formatted (and possibly only if log args are length 1 too?).

  dd: {
    trace_id: traceId
    span_id: parentId
  }

Actual Behavior

Converts json object to a string representation and prefixes with [dd.trace_id=${traceId} dd.span_id=${parentId}], resulting in loss of datadog json log functionality.

Steps to Reproduce the Problem

  1. Send a json formatted log
  2. View the log in datadog and see that it has turned into a string representation in the message and unable to use datadog json parsing features

Workaround

  1. Turn off log injection with environmental variable: DD_LOGS_INJECTION: false
  2. Import dd-trace from lambda layer
  3. Set dd key and value
    const context = tracer.scope().active()?.context();
    const log = {
      dd: {
        trace_id: context?.toTraceId(),
        span_id: context?.toSpanId(),
      },
      // ... other log keys and values
    };

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions