getsentry / sentry-react-native

Official Sentry SDK for React-Native
https://sentry.io
MIT License
1.54k stars 323 forks source link

Flatten Metrics Tags for Objects #3789

Closed daniel-johns-99 closed 3 weeks ago

daniel-johns-99 commented 1 month ago

Currently if you send a JSON object as a tag to Sentry Metrics, it appears on sentry as [Object object].

It would be nice to flatten the tag so that all values of the object are sent as individual tags.

The Python SDK does this already https://github.com/getsentry/sentry-python/blob/master/sentry_sdk/metrics.py#L692

krystofwoldrich commented 1 month ago

Hi, could you share a code snippet how you pass the tags object to the metrics functions?

The following snippet add tags from an object.

const moreTags = { appName: "Test" };
const myTags = { browser: "Firefox", app_version: "1.0.0" };
Sentry.metrics.increment("button_click", 1, {
  tags: {
    ...moreTags,
    ...myTags,
  },
});

This won't work (result will be [Object object]):

const myTags = { browser: "Firefox", app_version: "1.0.0" };
Sentry.metrics.increment("button_click", 1, {
  tags: {
    myTags,
  },
});
krystofwoldrich commented 3 weeks ago

In case the previous responses have not solved the issue, please feel free to comment here or open a new issue.

daniel-johns-99 commented 3 weeks ago

Hi @krystofwoldrich,

You are correct

const myTags = { browser: "Firefox", app_version: "1.0.0" };
Sentry.metrics.increment("button_click", 1, {
  tags: {
    myTags,
  },
});

Does not work and it would be nice to work so this is a feature request to flatten a JSON object.

I mentioned this works on Python: https://github.com/getsentry/sentry-python/blob/master/sentry_sdk/metrics.py#L692

The SDK develop page mentions that if the SDK has a way to support sending non-string values it can be sent https://develop.sentry.dev/sdk/metrics/#aggregator-behavior and being able to flatten a JSON object to key value should be achievable.

daniel-johns-99 commented 1 week ago

@krystofwoldrich Could we reopen? Its not solved yet.