Skip to content

Add helper function for interpolating logging statements #6725

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions