Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pino: Allow logging trace metadata under different keys #1664

Closed
drewcorlin1 opened this issue Sep 4, 2023 · 6 comments
Closed

Pino: Allow logging trace metadata under different keys #1664

drewcorlin1 opened this issue Sep 4, 2023 · 6 comments

Comments

@drewcorlin1
Copy link
Contributor

drewcorlin1 commented Sep 4, 2023

Is your feature request related to a problem? Please describe

The current pino instrumentation from @opentelemetry/instrumentation-pino injects 3 fields into each log, trace_id, span_id and trace_flags. These fields are useful, but the snake case naming is slightly problematic in my case, where my company has strict logging standards and we'd like to use camelCase.

Describe the solution you'd like to see

Allowing a different set of keys to be used in the config (this is assuming you are configuring the instrumentation via getNodeAutoInstrumentations from @opentelemetry/auto-instrumentations-node).

'@opentelemetry/instrumentation-pino': {
  camelCase: true
}

Describe alternatives you've considered

Reformatting the log manually, via the logHook config.

'@opentelemetry/instrumentation-pino': {
    logHook: (span, record) => {
      // Reformat the injected log fields to use camelCase, eg. trace_id -> traceId
      const context = span.spanContext();
      record.traceId = context.traceId;
      record.spanId = context.spanId;
      record.traceFlags = context.traceFlags;

      // Be extra safe, in case someone manually logged these fields, even though they shouldn't
      if (record.trace_id === context.traceId) delete record.trace_id;
      if (record.span_id === context.spanId) delete record.span_id;
      if (record.trace_flags === context.traceFlags) delete record.trace_flags;
    },
  },

Additional context

@Flarna
Copy link
Member

Flarna commented Sep 4, 2023

I think it would be more flexible to allow to override the actual key names instead of adding just one more fixed set. e.g

'@opentelemetry/instrumentation-pino': {
  traceIdKey: 'traceId', // default is 'trace_id
  spanIdKey: 'span.id', // default is 'span_id'
  trace_flags: 'my-trace-flags'  // defaults to 'trace_flags'
}

And well, it would be nice to have the same/similar config for other log instrumentations like winston,...

@drewcorlin1 drewcorlin1 changed the title Pino: Allow logging trace metadata under camelCase keys Pino: Allow logging trace metadata under different keys Sep 5, 2023
Copy link
Contributor

github-actions bot commented Nov 6, 2023

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the stale label Nov 6, 2023
@drewcorlin1
Copy link
Contributor Author

Not stale

@github-actions github-actions bot removed the stale label Nov 13, 2023
@mbrevda
Copy link

mbrevda commented Dec 12, 2023

This could also be useful for specific log destinations. For example. GCP requires the following format:

   const trace = `projects/${projectId}/traces/${traceId}`;
      res['logging.googleapis.com/trace'] = trace;
    }
    res['logging.googleapis.com/trace_sampled'] = traceFlags;
    res['logging.googleapis.com/spanId'] = spanId;

@trentm
Copy link
Contributor

trentm commented Feb 25, 2024

@drewcorlin1 This can be closed now, right (it was handled by #1867)?

@drewcorlin1
Copy link
Contributor Author

@drewcorlin1 This can be closed now, right (it was handled by #1867)?

Yes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants