Skip to content

Issue with log.Ctx and event context #756

@sonalys

Description

@sonalys

There is a very confusing problem for me when using zerolog:

log.Ctx(ctx) doesn't insert the provided context in the Event, resulting in logs without telemetry data

The solution is quite ugly:

import "github.com/rs/zerolog/log"

...

log.
  Ctx(ctx). // Retrieves the logger from context, without setting the context for Event.
  Info(). // Creates an event
  Ctx(ctx). // Sets the ctx for the Event so we can retrieve telemetry data.
  ...

I think it would be highly convenient that we do not have to set the event context if the log is already created from a context.
Am I doing something wrong here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions