Skip to content

Commit

Permalink
capture envelope
Browse files Browse the repository at this point in the history
  • Loading branch information
sl0thentr0py committed Feb 26, 2024
1 parent 73e5e04 commit 9569bf9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
11 changes: 6 additions & 5 deletions sentry-ruby/lib/sentry/envelope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ class Item
STACKTRACE_FRAME_LIMIT_ON_OVERSIZED_PAYLOAD = 500
MAX_SERIALIZED_PAYLOAD_SIZE = 1024 * 1000

attr_accessor :headers, :payload
attr_accessor :headers, :payload, :is_json

def initialize(headers, payload)
def initialize(headers, payload, is_json: true)
@headers = headers
@payload = payload
@is_json = is_json
end

def type
@headers[:type] || 'event'
end

def to_s
[JSON.generate(@headers), JSON.generate(@payload)].join("\n")
[JSON.generate(@headers), @is_json ? JSON.generate(@payload) : @payload].join("\n")
end

def serialize
Expand Down Expand Up @@ -78,8 +79,8 @@ def initialize(headers = {})
@items = []
end

def add_item(headers, payload)
@items << Item.new(headers, payload)
def add_item(headers, payload, is_json: true)
@items << Item.new(headers, payload, is_json: is_json)
end

def item_types
Expand Down
13 changes: 12 additions & 1 deletion sentry-ruby/lib/sentry/metrics/aggregator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,19 @@ def flush(force: false)
return if flushable_buckets.empty?

Check warning on line 70 in sentry-ruby/lib/sentry/metrics/aggregator.rb

View check run for this annotation

Codecov / codecov/patch

sentry-ruby/lib/sentry/metrics/aggregator.rb#L69-L70

Added lines #L69 - L70 were not covered by tests

payload = serialize_buckets(flushable_buckets)
envelope = Envelope.new
envelope.add_item(

Check warning on line 74 in sentry-ruby/lib/sentry/metrics/aggregator.rb

View check run for this annotation

Codecov / codecov/patch

sentry-ruby/lib/sentry/metrics/aggregator.rb#L72-L74

Added lines #L72 - L74 were not covered by tests
{ type: 'statsd', length: payload.bytesize },
payload,
is_json: false
)

log_debug("[Metrics::Aggregator] flushing buckets: #{flushable_buckets}")
log_debug("[Metrics::Aggregator] payload: #{payload}")

Check warning on line 81 in sentry-ruby/lib/sentry/metrics/aggregator.rb

View check run for this annotation

Codecov / codecov/patch

sentry-ruby/lib/sentry/metrics/aggregator.rb#L80-L81

Added lines #L80 - L81 were not covered by tests

Sentry.background_worker.perform do
@client.transport.send_envelope(envelope)

Check warning on line 84 in sentry-ruby/lib/sentry/metrics/aggregator.rb

View check run for this annotation

Codecov / codecov/patch

sentry-ruby/lib/sentry/metrics/aggregator.rb#L83-L84

Added lines #L83 - L84 were not covered by tests
end
end

def kill
Expand Down Expand Up @@ -136,7 +147,7 @@ def serialize_buckets(buckets)
timestamp_buckets.map do |metric_key, metric|
type, key, unit, tags = metric_key
values = metric.serialize.join(':')
sanitized_tags = tags.map { |k, v| "#{sanitize_key(k)}:#{sanitize_value(v)}"}.join(',')
sanitized_tags = tags.map { |k, v| "#{sanitize_key(k)}:#{sanitize_value(v)}" }.join(',')

Check warning on line 150 in sentry-ruby/lib/sentry/metrics/aggregator.rb

View check run for this annotation

Codecov / codecov/patch

sentry-ruby/lib/sentry/metrics/aggregator.rb#L146-L150

Added lines #L146 - L150 were not covered by tests

"#{sanitize_key(key)}@#{unit}:#{values}|#{type}|\##{sanitized_tags}|T#{timestamp}"

Check warning on line 152 in sentry-ruby/lib/sentry/metrics/aggregator.rb

View check run for this annotation

Codecov / codecov/patch

sentry-ruby/lib/sentry/metrics/aggregator.rb#L152

Added line #L152 was not covered by tests
end
Expand Down

0 comments on commit 9569bf9

Please sign in to comment.