Commit 3f94dc1
authored
feat(tracing): Allow storing span metadata (#5464)
This adds span metadata to the `TransactionMetadata` type and the default value given to the `metadata` property in the `Transaction` constructor. I chose to add a property to `TransactionMetadata` rather than create a new `SpanMetadata` type/property which would live on the `Span` class because by doing the former, we don't have to worry about looping over the spans and deleting the metadata before the transaction is sent - everything in `transaction.metadata` (which becomes `event.sdkProcessingMetadata`) is already cleared when the envelope is created[1].
In order to not have to assert on its existence every time it's used, I made `spanMetadata` a required property of `TransactionMetadata`. In order to satisfy that required-ness, a few other things had to happen:
- It had to be initialized in the `Transaction` constructor. (Note that there should never be incoming span metadata because the only span at that point is the transaction itself, and its metadata can and does already live in the main `metadata` object. This means there's no need to do `span: metadata.span || {}` when initializing it. )
- The metadata passed to the constructor in the transaction context needed to become a partial (which it effectively already was, since until now all properties have been optional).
- The metadata passed to `setMetadata` similarly had to become a partial.
[1] https://github.com/getsentry/sentry-javascript/blob/8a06b16d605ca3a1fa6c9af2a701f332e39799ed/packages/core/src/envelope.ts#L861 parent db9ab7c commit 3f94dc1
2 files changed
+11
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
46 | 50 | | |
47 | 51 | | |
48 | 52 | | |
| |||
89 | 93 | | |
90 | 94 | | |
91 | 95 | | |
92 | | - | |
| 96 | + | |
93 | 97 | | |
94 | 98 | | |
95 | 99 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| |||
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
96 | | - | |
| 96 | + | |
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
| |||
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
150 | 153 | | |
151 | 154 | | |
152 | 155 | | |
| |||
0 commit comments