|
| 1 | +import functools |
| 2 | +import re |
| 3 | + |
| 4 | +_KNOWN_TAGS = { |
| 5 | + "sentry.cocoa", |
| 6 | + "sentry.dart", |
| 7 | + "sentry.dotnet", |
| 8 | + "sentry.elixir", |
| 9 | + "sentry.go", |
| 10 | + "sentry.java", |
| 11 | + "sentry.javascript.angular", |
| 12 | + "sentry.javascript.browser", |
| 13 | + "sentry.javascript.capacitor", |
| 14 | + "sentry.javascript.cordova", |
| 15 | + "sentry.javascript.deno", |
| 16 | + "sentry.javascript.electron", |
| 17 | + "sentry.javascript.ember", |
| 18 | + "sentry.javascript.gatsby", |
| 19 | + "sentry.javascript.nextjs", |
| 20 | + "sentry.javascript.node", |
| 21 | + "sentry.javascript.react", |
| 22 | + "sentry.javascript.react.native", |
| 23 | + "sentry.javascript.remix", |
| 24 | + "sentry.javascript.serverless", |
| 25 | + "sentry.javascript.svelte", |
| 26 | + "sentry.javascript.sveltekit", |
| 27 | + "sentry.javascript.vue", |
| 28 | + "sentry.kubernetes", |
| 29 | + "sentry.native.android", |
| 30 | + "sentry.native.dotnet", |
| 31 | + "sentry.native.unity", |
| 32 | + "sentry.native.unreal", |
| 33 | + "sentry.objc", |
| 34 | + "sentry.perl", |
| 35 | + "sentry.php", |
| 36 | + "sentry.python", |
| 37 | + "sentry.ruby", |
| 38 | + "sentry.rust", |
| 39 | + "sentry.swift", |
| 40 | +} |
| 41 | + |
| 42 | + |
| 43 | +_SYNONYMOUS_TAGS = { |
| 44 | + "sentry.cordova": "sentery.javascript.cordova", |
| 45 | + "sentry.electron": "sentry.javascript.electron", |
| 46 | + "sentry.javascript.angular.ivy": "sentry.javascript.angular", |
| 47 | + "sentry.javascript.node.experimental": "sentry.javascript.node", |
| 48 | + "sentry.javascript.react.expo": "sentry.javascript.react", |
| 49 | + "sentry.javascript.react.native.expo": "sentry.javascript.react.native", |
| 50 | + "sentry.laravel": "sentry.php.laravel", |
| 51 | + "sentry.react": "sentry.javascript.react", |
| 52 | + "sentry.symfony": "sentry.php.symfony", |
| 53 | + "sentry.unity": "sentry.native.unity", |
| 54 | +} |
| 55 | + |
| 56 | +# TODO: Should we be grouping by origin SDK instead? (For example, should we be |
| 57 | +# combining all flutter events rather than all native events?) |
| 58 | +# See https://github.com/getsentry/sentry/pull/59504#discussion_r1385483963 |
| 59 | + |
| 60 | + |
| 61 | +@functools.lru_cache(maxsize=300) |
| 62 | +def normalize_sdk_tag(tag: str) -> str: |
| 63 | + """ |
| 64 | + Normalize tags coming from SDKs to more manageable canonical form, by: |
| 65 | +
|
| 66 | + - combining synonymous tags (`sentry.react` -> `sentry.javascript.react`), |
| 67 | + - ignoring framework differences (`sentry.python.flask` and `sentry.python.django` -> `sentry.python`) |
| 68 | + - collapsing all community/third-party SDKs into a single `other` category |
| 69 | +
|
| 70 | + Note: Some platforms may keep their framework-specific values, as needed for analytics. |
| 71 | + """ |
| 72 | + |
| 73 | + # replace non-word characters with dots (normalize sentry-foo to sentry.foo) |
| 74 | + tag = re.sub(r"[\W_]+", ".", tag) |
| 75 | + |
| 76 | + # collapse known synonymous tags |
| 77 | + tag = _SYNONYMOUS_TAGS.get(tag, tag) |
| 78 | + |
| 79 | + # ignore non-sentry SDK tags |
| 80 | + if not tag.startswith("sentry."): |
| 81 | + return "other" |
| 82 | + |
| 83 | + # collapse tags other than JavaScript / Native to their top-level SDK |
| 84 | + |
| 85 | + if not tag.split(".")[1] in {"javascript", "native"}: |
| 86 | + tag = ".".join(tag.split(".", 2)[0:2]) |
| 87 | + |
| 88 | + if tag.split(".")[1] == "native": |
| 89 | + tag = ".".join(tag.split(".", 3)[0:3]) |
| 90 | + |
| 91 | + if tag not in _KNOWN_TAGS: |
| 92 | + tag = "other" |
| 93 | + |
| 94 | + return tag |
0 commit comments