Skip to content

Add helper function for interpolating logging statements #6725

Closed
@AbhiPrasad

Description

@AbhiPrasad

Problem Statement

https://twitter.com/branmcconnell/status/1612828176102883331

Sentry has a Message Interface, which is contained in the logentry field. This allows us to store a paramaterized representation of the message, which helps with grouping and other product features.

We should expose a helper function, that will set the logentry field when captured by captureMessage.

Solution Brainstorm

function parametrize(strings, ...values) {
  let formatted = new String(String.raw(strings, ...values));
  formatted.__sentry_template_string__ = strings.join("\x00").replace(/%/g, "%%").replace(/\x00/g, "%s");
  formatted.__sentry_template_values__ = values;
  return formatted;
}

The paramaterize function is a tag template.

The __sentry_template_string__ can then be consumed by client processing to set a logentry on `captureMessage.

Sentry.captureMessage(parametrize`This is a log statement with ${x} and ${y} params`)

See https://github.com/getsentry/sentry-python/blob/dd8bfe37d2ab369eaa481a93484d4140fd964842/sentry_sdk/integrations/logging.py#L253-L256

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Status

    Waiting for: Product Owner

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions