sentry-ruby-core 4.6.5 → 4.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4440f6ad3a4fd52dc9bd94c15a64e239a6957aca9adc7a410e8bd787d124bcae
4
- data.tar.gz: c6736aba5112331695e81adc496f3c6ee5581ae2ee419ba880c912eb20cedde9
3
+ metadata.gz: a9ceb36eb4db5018e7b309949fa8ae468c07f0687c0227fd9f8b20e68e216776
4
+ data.tar.gz: e214379b67e80cb89c7f70a36739bd2f067af6fa9227acf125349a2aef2c8ea4
5
5
  SHA512:
6
- metadata.gz: e38a7ad731a84ee1886c341f8e6484c2019ad328b0a7c3bd93583d1f3056088f5f8e050bf0d0b764a5938c80ca7e704608aa2a107e6b9f915f76cb6dc701e1dc
7
- data.tar.gz: fd137796bb363205ba78929c987b1cb1e3f7f494058e9fb8a31348ef29dd071994ec30a816b7de3befcdc018f91bc437cfade282fa65aa57952ac0e863580291
6
+ metadata.gz: 2bfdb4d169ba1d9c896273401df8891b51f5fc016609154a1ec02bf064bf956bc4ce69ab85cafc4c82001ccaf475d86bc18d4064f1cdd8563ae03761a0245604
7
+ data.tar.gz: 53ce1e1f6d4957a1c3ad327cc7e51d154da1da32c863ad21fd0ce3aca09273fa794c08b39ee7adfafd96e7afa30555b87a2f2013b345906a0218001d177d3bec
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2020 st0012
3
+ Copyright (c) 2020 Sentry
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/lib/sentry/client.rb CHANGED
@@ -57,10 +57,10 @@ module Sentry
57
57
  end
58
58
  end
59
59
 
60
- def event_from_message(message, hint = {})
60
+ def event_from_message(message, hint = {}, backtrace: nil)
61
61
  integration_meta = Sentry.integrations[hint[:integration]]
62
62
  event = Event.new(configuration: configuration, integration_meta: integration_meta, message: message)
63
- event.add_threads_interface(backtrace: caller)
63
+ event.add_threads_interface(backtrace: backtrace || caller)
64
64
  event
65
65
  end
66
66
 
@@ -324,6 +324,15 @@ module Sentry
324
324
  log_error("Error detecting release", e, debug: debug)
325
325
  end
326
326
 
327
+ def csp_report_uri
328
+ if dsn && dsn.valid?
329
+ uri = dsn.csp_report_uri
330
+ uri += "&sentry_release=#{CGI.escape(release)}" if release && !release.empty?
331
+ uri += "&sentry_environment=#{CGI.escape(environment)}" if environment && !environment.empty?
332
+ uri
333
+ end
334
+ end
335
+
327
336
  private
328
337
 
329
338
  def excluded_exception?(incoming_exception)
@@ -421,7 +430,7 @@ module Sentry
421
430
  end
422
431
 
423
432
  def environment_from_env
424
- ENV['SENTRY_CURRENT_ENV'] || ENV['SENTRY_ENVIRONMENT'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'default'
433
+ ENV['SENTRY_CURRENT_ENV'] || ENV['SENTRY_ENVIRONMENT'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
425
434
  end
426
435
 
427
436
  def server_name_from_env
data/lib/sentry/dsn.rb CHANGED
@@ -40,6 +40,10 @@ module Sentry
40
40
  server
41
41
  end
42
42
 
43
+ def csp_report_uri
44
+ "#{server}/api/#{project_id}/security/?sentry_key=#{public_key}"
45
+ end
46
+
43
47
  def envelope_endpoint
44
48
  "#{path}/api/#{project_id}/envelope/"
45
49
  end
data/lib/sentry/hub.rb CHANGED
@@ -90,10 +90,10 @@ module Sentry
90
90
  end
91
91
 
92
92
  def capture_exception(exception, **options, &block)
93
- return unless current_client
94
-
95
93
  check_argument_type!(exception, ::Exception)
96
94
 
95
+ return unless current_client
96
+
97
97
  options[:hint] ||= {}
98
98
  options[:hint][:exception] = exception
99
99
  event = current_client.event_from_exception(exception, options[:hint])
@@ -104,19 +104,22 @@ module Sentry
104
104
  end
105
105
 
106
106
  def capture_message(message, **options, &block)
107
+ check_argument_type!(message, ::String)
108
+
107
109
  return unless current_client
108
110
 
109
111
  options[:hint] ||= {}
110
112
  options[:hint][:message] = message
111
- event = current_client.event_from_message(message, options[:hint])
113
+ backtrace = options.delete(:backtrace)
114
+ event = current_client.event_from_message(message, options[:hint], backtrace: backtrace)
112
115
  capture_event(event, **options, &block)
113
116
  end
114
117
 
115
118
  def capture_event(event, **options, &block)
116
- return unless current_client
117
-
118
119
  check_argument_type!(event, Sentry::Event)
119
120
 
121
+ return unless current_client
122
+
120
123
  hint = options.delete(:hint) || {}
121
124
  scope = current_scope.dup
122
125
 
@@ -135,6 +138,8 @@ module Sentry
135
138
  end
136
139
 
137
140
  def add_breadcrumb(breadcrumb, hint: {})
141
+ return unless configuration.enabled_in_current_env?
142
+
138
143
  if before_breadcrumb = current_client.configuration.before_breadcrumb
139
144
  breadcrumb = before_breadcrumb.call(breadcrumb, hint)
140
145
  end
@@ -57,7 +57,7 @@ module Sentry
57
57
  request.POST
58
58
  elsif request.body # JSON requests, etc
59
59
  data = request.body.read(MAX_BODY_LIMIT)
60
- data = data.force_encoding(Encoding::UTF_8) if data.respond_to?(:force_encoding)
60
+ data = encode_to_utf_8(data.to_s)
61
61
  request.body.rewind
62
62
  data
63
63
  end
@@ -76,7 +76,8 @@ module Sentry
76
76
  # Rack stores headers as HTTP_WHAT_EVER, we need What-Ever
77
77
  key = key.sub(/^HTTP_/, "")
78
78
  key = key.split('_').map(&:capitalize).join('-')
79
- memo[key] = value.to_s
79
+
80
+ memo[key] = encode_to_utf_8(value.to_s)
80
81
  rescue StandardError => e
81
82
  # Rails adds objects to the Rack env that can sometimes raise exceptions
82
83
  # when `to_s` is called.
@@ -87,6 +88,18 @@ module Sentry
87
88
  end
88
89
  end
89
90
 
91
+ def encode_to_utf_8(value)
92
+ if value.encoding != Encoding::UTF_8 && value.respond_to?(:force_encoding)
93
+ value = value.dup.force_encoding(Encoding::UTF_8)
94
+ end
95
+
96
+ if !value.valid_encoding?
97
+ value = value.scrub
98
+ end
99
+
100
+ value
101
+ end
102
+
90
103
  def is_skippable_header?(key)
91
104
  key.upcase != key || # lower-case envs aren't real http headers
92
105
  key == "HTTP_COOKIE" || # Cookies don't go here, they go somewhere else
data/lib/sentry/scope.rb CHANGED
@@ -23,6 +23,7 @@ module Sentry
23
23
  event.user = user.merge(event.user)
24
24
  event.extra = extra.merge(event.extra)
25
25
  event.contexts = contexts.merge(event.contexts)
26
+ event.transaction = transaction_name if transaction_name
26
27
 
27
28
  if span
28
29
  event.contexts[:trace] = span.get_trace_context
@@ -30,7 +31,6 @@ module Sentry
30
31
 
31
32
  event.fingerprint = fingerprint
32
33
  event.level = level
33
- event.transaction = transaction_names.last
34
34
  event.breadcrumbs = breadcrumbs
35
35
  event.rack_env = rack_env if rack_env
36
36
 
@@ -1,3 +1,3 @@
1
1
  module Sentry
2
- VERSION = "4.6.5"
2
+ VERSION = "4.7.3"
3
3
  end
data/lib/sentry-ruby.rb CHANGED
@@ -90,6 +90,18 @@ module Sentry
90
90
  @background_worker = Sentry::BackgroundWorker.new(config)
91
91
  end
92
92
 
93
+ # Returns an uri for security policy reporting that's generated from the given DSN
94
+ # (To learn more about security policy reporting: https://docs.sentry.io/product/security-policy-reporting/)
95
+ #
96
+ # It returns nil if
97
+ #
98
+ # 1. The SDK is not initialized yet.
99
+ # 2. The DSN is not provided or is invalid.
100
+ def csp_report_uri
101
+ return unless initialized?
102
+ configuration.csp_report_uri
103
+ end
104
+
93
105
  # Returns the main thread's active hub.
94
106
  def get_main_hub
95
107
  @main_hub
@@ -6,7 +6,7 @@ Gem::Specification.new do |spec|
6
6
  spec.authors = ["Sentry Team"]
7
7
  spec.description = spec.summary = "A gem that provides a client interface for the Sentry error logger"
8
8
  spec.email = "accounts@sentry.io"
9
- spec.license = 'Apache-2.0'
9
+ spec.license = 'MIT'
10
10
  spec.homepage = "https://github.com/getsentry/sentry-ruby"
11
11
 
12
12
  spec.platform = Gem::Platform::RUBY
data/sentry-ruby.gemspec CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |spec|
6
6
  spec.authors = ["Sentry Team"]
7
7
  spec.description = spec.summary = "A gem that provides a client interface for the Sentry error logger"
8
8
  spec.email = "accounts@sentry.io"
9
- spec.license = 'Apache-2.0'
9
+ spec.license = 'MIT'
10
10
  spec.homepage = "https://github.com/getsentry/sentry-ruby"
11
11
 
12
12
  spec.platform = Gem::Platform::RUBY
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sentry-ruby-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.6.5
4
+ version: 4.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sentry Team
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-08-12 00:00:00.000000000 Z
11
+ date: 2021-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -103,7 +103,7 @@ files:
103
103
  - sentry-ruby.gemspec
104
104
  homepage: https://github.com/getsentry/sentry-ruby
105
105
  licenses:
106
- - Apache-2.0
106
+ - MIT
107
107
  metadata:
108
108
  homepage_uri: https://github.com/getsentry/sentry-ruby
109
109
  source_code_uri: https://github.com/getsentry/sentry-ruby