stack_trace 0.2.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.tool-versions +1 -0
  3. data/CODE_OF_CONDUCT.md +84 -0
  4. data/Gemfile +6 -1
  5. data/Gemfile.lock +19 -23
  6. data/LICENSE.txt +1 -1
  7. data/README.md +15 -191
  8. data/Rakefile +8 -1
  9. data/ext/stack_trace/configuration.c +23 -0
  10. data/ext/stack_trace/configuration.h +6 -0
  11. data/ext/stack_trace/current_trace.c +43 -0
  12. data/ext/stack_trace/current_trace.h +7 -0
  13. data/ext/stack_trace/debug.c +43 -0
  14. data/ext/stack_trace/debug.h +37 -0
  15. data/ext/stack_trace/event_producer.c +65 -0
  16. data/ext/stack_trace/event_producer.h +3 -0
  17. data/ext/stack_trace/event_store.c +109 -0
  18. data/ext/stack_trace/event_store.h +5 -0
  19. data/ext/stack_trace/extconf.rb +7 -0
  20. data/ext/stack_trace/sidecar.c +77 -0
  21. data/ext/stack_trace/sidecar.h +1 -0
  22. data/ext/stack_trace/span.c +106 -0
  23. data/ext/stack_trace/span.h +9 -0
  24. data/ext/stack_trace/stack_trace.c +54 -0
  25. data/ext/stack_trace/trace.c +132 -0
  26. data/ext/stack_trace/trace.h +8 -0
  27. data/ext/stack_trace/types/event.h +31 -0
  28. data/ext/stack_trace/types/span.h +22 -0
  29. data/ext/stack_trace/types/trace.h +15 -0
  30. data/ext/stack_trace/utils.c +8 -0
  31. data/ext/stack_trace/utils.h +1 -0
  32. data/lib/stack_trace/argument_extractor.rb +22 -0
  33. data/lib/stack_trace/configuration.rb +2 -57
  34. data/lib/stack_trace/patch/class.rb +7 -0
  35. data/lib/stack_trace/patch/false_class.rb +7 -0
  36. data/lib/stack_trace/patch/nil_class.rb +7 -0
  37. data/lib/stack_trace/patch/numeric.rb +7 -0
  38. data/lib/stack_trace/patch/object.rb +7 -0
  39. data/lib/stack_trace/patch/symbol.rb +7 -0
  40. data/lib/stack_trace/patch/true_class.rb +7 -0
  41. data/lib/stack_trace/version.rb +3 -1
  42. data/lib/stack_trace.rb +30 -34
  43. data/stack_trace.gemspec +22 -20
  44. metadata +45 -77
  45. data/.gitignore +0 -11
  46. data/.travis.yml +0 -7
  47. data/bin/console +0 -14
  48. data/bin/setup +0 -8
  49. data/lib/stack_trace/integration/rspec.rb +0 -79
  50. data/lib/stack_trace/module_extensions.rb +0 -13
  51. data/lib/stack_trace/setup.rb +0 -62
  52. data/lib/stack_trace/span.rb +0 -94
  53. data/lib/stack_trace/trace.rb +0 -83
@@ -1,83 +0,0 @@
1
- # frozen-string-literal: true
2
-
3
- require "securerandom"
4
-
5
- module StackTrace
6
- class Trace
7
- TRACE_START_EVENTS = %i(call c_call).freeze
8
- TRACE_END_EVENTS = %i(return c_return).freeze
9
- TRACE_RAISE_EVENT = :raise
10
-
11
- class << self
12
- def track(trace_point)
13
- current.add(trace_point) if trackable?(trace_point)
14
- end
15
-
16
- def start
17
- @current = new
18
- end
19
-
20
- def current
21
- @current ||= new
22
- end
23
-
24
- def as_json
25
- current.as_json
26
- end
27
-
28
- private
29
-
30
- def trackable?(trace_point)
31
- trace_point.defined_class&.trace_method?(trace_point.method_id)
32
- end
33
- end
34
-
35
- attr_reader :uuid, :spans
36
-
37
- def initialize
38
- @uuid = SecureRandom.uuid
39
- @spans = []
40
- end
41
-
42
- def add(trace_point)
43
- case trace_point.event
44
- when *TRACE_START_EVENTS
45
- create_new_span(trace_point)
46
- when *TRACE_END_EVENTS
47
- close_current_span(trace_point)
48
- else
49
- apply_exception_to_current_span(trace_point)
50
- end
51
- end
52
-
53
- def as_json
54
- {
55
- uuid: uuid,
56
- spans: spans.map(&:as_json)
57
- }
58
- end
59
-
60
- def <<(span)
61
- spans << span
62
- end
63
-
64
- private
65
-
66
- def create_new_span(trace_point)
67
- span = Span.start_from(trace_point, container)
68
- container << (@active_span = span)
69
- end
70
-
71
- def close_current_span(trace_point)
72
- @active_span = @active_span&.close(trace_point)
73
- end
74
-
75
- def apply_exception_to_current_span(trace_point)
76
- @active_span.exception = trace_point.raised_exception
77
- end
78
-
79
- def container
80
- @active_span || self
81
- end
82
- end
83
- end