@@ -23,7 +23,10 @@ import (
23
23
"github.com/getsentry/vroom/internal/storageutil"
24
24
)
25
25
26
- const maxUniqueFunctionsPerProfile = 100
26
+ const (
27
+ maxUniqueFunctionsPerProfile = 100
28
+ unsampledProfileID = "00000000000000000000000000000000"
29
+ )
27
30
28
31
func (env * environment ) postProfile (w http.ResponseWriter , r * http.Request ) {
29
32
ctx := r .Context ()
@@ -71,24 +74,34 @@ func (env *environment) postProfile(w http.ResponseWriter, r *http.Request) {
71
74
p .Normalize ()
72
75
s .Finish ()
73
76
74
- s = sentry .StartSpan (ctx , "gcs.write" )
75
- s .Description = "Write profile to GCS"
76
- err = storageutil .CompressedWrite (ctx , env .storage , p .StoragePath (), p )
77
- s .Finish ()
78
- if err != nil {
79
- if errors .Is (err , context .DeadlineExceeded ) {
80
- // This is a transient error, we'll retry
81
- w .WriteHeader (http .StatusTooManyRequests )
82
- } else {
83
- // These errors won't be retried
84
- hub .CaptureException (err )
85
- if code := gcerrors .Code (err ); code == gcerrors .FailedPrecondition {
86
- w .WriteHeader (http .StatusPreconditionFailed )
77
+ if ! p .IsSampled () {
78
+ // if we're dealing with an unsampled profile
79
+ // we'll assign the special "000....00" profile ID
80
+ // so that we can handle it accordingly either in
81
+ // either of snuba/sentry/front-end
82
+ p .SetProfileID (unsampledProfileID )
83
+ }
84
+
85
+ if p .IsSampled () {
86
+ s = sentry .StartSpan (ctx , "gcs.write" )
87
+ s .Description = "Write profile to GCS"
88
+ err = storageutil .CompressedWrite (ctx , env .storage , p .StoragePath (), p )
89
+ s .Finish ()
90
+ if err != nil {
91
+ if errors .Is (err , context .DeadlineExceeded ) {
92
+ // This is a transient error, we'll retry
93
+ w .WriteHeader (http .StatusTooManyRequests )
87
94
} else {
88
- w .WriteHeader (http .StatusInternalServerError )
95
+ // These errors won't be retried
96
+ hub .CaptureException (err )
97
+ if code := gcerrors .Code (err ); code == gcerrors .FailedPrecondition {
98
+ w .WriteHeader (http .StatusPreconditionFailed )
99
+ } else {
100
+ w .WriteHeader (http .StatusInternalServerError )
101
+ }
89
102
}
103
+ return
90
104
}
91
- return
92
105
}
93
106
94
107
s = sentry .StartSpan (ctx , "processing" )
@@ -102,35 +115,40 @@ func (env *environment) postProfile(w http.ResponseWriter, r *http.Request) {
102
115
}
103
116
104
117
if len (callTrees ) > 0 {
105
- s = sentry .StartSpan (ctx , "processing" )
106
- s .Description = "Find occurrences"
107
- occurrences := occurrence .Find (p , callTrees )
108
- s .Finish ()
118
+ // if the profile was not sampled we skip find_occurrences since we're only
119
+ // interested in extracting data to improve functions aggregations not in
120
+ // using it for finding occurrences of an issue
121
+ if p .IsSampled () {
122
+ s = sentry .StartSpan (ctx , "processing" )
123
+ s .Description = "Find occurrences"
124
+ occurrences := occurrence .Find (p , callTrees )
125
+ s .Finish ()
109
126
110
- // Filter in-place occurrences without a type.
111
- var i int
112
- for _ , o := range occurrences {
113
- if o .Type != occurrence .NoneType {
114
- occurrences [i ] = o
115
- i ++
127
+ // Filter in-place occurrences without a type.
128
+ var i int
129
+ for _ , o := range occurrences {
130
+ if o .Type != occurrence .NoneType {
131
+ occurrences [i ] = o
132
+ i ++
133
+ }
116
134
}
117
- }
118
- occurrences = occurrences [:i ]
119
- s = sentry .StartSpan (ctx , "processing" )
120
- s .Description = "Build Kafka message batch"
121
- occurrenceMessages , err := occurrence .GenerateKafkaMessageBatch (occurrences )
122
- s .Finish ()
123
- if err != nil {
124
- // Report the error but don't fail profile insertion
125
- hub .CaptureException (err )
126
- } else {
135
+ occurrences = occurrences [:i ]
127
136
s = sentry .StartSpan (ctx , "processing" )
128
- s .Description = "Send occurrences to Kafka "
129
- err = env . occurrencesWriter . WriteMessages ( ctx , occurrenceMessages ... )
137
+ s .Description = "Build Kafka message batch "
138
+ occurrenceMessages , err := occurrence . GenerateKafkaMessageBatch ( occurrences )
130
139
s .Finish ()
131
140
if err != nil {
132
141
// Report the error but don't fail profile insertion
133
142
hub .CaptureException (err )
143
+ } else {
144
+ s = sentry .StartSpan (ctx , "processing" )
145
+ s .Description = "Send occurrences to Kafka"
146
+ err = env .occurrencesWriter .WriteMessages (ctx , occurrenceMessages ... )
147
+ s .Finish ()
148
+ if err != nil {
149
+ // Report the error but don't fail profile insertion
150
+ hub .CaptureException (err )
151
+ }
134
152
}
135
153
}
136
154
@@ -164,31 +182,33 @@ func (env *environment) postProfile(w http.ResponseWriter, r *http.Request) {
164
182
}
165
183
}
166
184
167
- // Prepare profile Kafka message
168
- s = sentry .StartSpan (ctx , "processing" )
169
- s .Description = "Marshal profile metadata Kafka message"
170
- b , err := json .Marshal (buildProfileKafkaMessage (p ))
171
- s .Finish ()
172
- if err != nil {
173
- hub .CaptureException (err )
174
- w .WriteHeader (http .StatusInternalServerError )
175
- return
176
- }
185
+ if p .IsSampled () {
186
+ // Prepare profile Kafka message
187
+ s = sentry .StartSpan (ctx , "processing" )
188
+ s .Description = "Marshal profile metadata Kafka message"
189
+ b , err := json .Marshal (buildProfileKafkaMessage (p ))
190
+ s .Finish ()
191
+ if err != nil {
192
+ hub .CaptureException (err )
193
+ w .WriteHeader (http .StatusInternalServerError )
194
+ return
195
+ }
177
196
178
- s = sentry .StartSpan (ctx , "processing" )
179
- s .Description = "Send profile metadata to Kafka"
180
- err = env .profilingWriter .WriteMessages (ctx , kafka.Message {
181
- Topic : env .config .Profiling .ProfilesKafkaTopic ,
182
- Value : b ,
183
- })
184
- s .Finish ()
185
- hub .Scope ().SetContext ("Profile metadata Kafka payload" , map [string ]interface {}{
186
- "Size" : len (b ),
187
- })
188
- if err != nil {
189
- hub .CaptureException (err )
190
- w .WriteHeader (http .StatusInternalServerError )
191
- return
197
+ s = sentry .StartSpan (ctx , "processing" )
198
+ s .Description = "Send profile metadata to Kafka"
199
+ err = env .profilingWriter .WriteMessages (ctx , kafka.Message {
200
+ Topic : env .config .Profiling .ProfilesKafkaTopic ,
201
+ Value : b ,
202
+ })
203
+ s .Finish ()
204
+ hub .Scope ().SetContext ("Profile metadata Kafka payload" , map [string ]interface {}{
205
+ "Size" : len (b ),
206
+ })
207
+ if err != nil {
208
+ hub .CaptureException (err )
209
+ w .WriteHeader (http .StatusInternalServerError )
210
+ return
211
+ }
192
212
}
193
213
194
214
w .WriteHeader (http .StatusNoContent )
0 commit comments