|
21 | 21 | end |
22 | 22 | end |
23 | 23 |
|
24 | | - let(:logs) do |
25 | | - Sentry.get_current_client.log_event_buffer.pending_events |
26 | | - end |
27 | | - |
28 | 24 | ["info", "warn", "error", "fatal"].each do |level| |
29 | 25 | describe "##{level}" do |
30 | 26 | it "logs using default logger and LogEvent logger with extra attributes" do |
31 | 27 | payload = { user_id: 123, action: "create" } |
32 | 28 |
|
33 | 29 | Sentry.logger.public_send(level, "Hello World", payload) |
34 | 30 |
|
35 | | - expect(logs).to_not be_empty |
| 31 | + expect(sentry_logs).to_not be_empty |
36 | 32 |
|
37 | | - log_event = logs.last |
| 33 | + log_event = sentry_logs.last |
38 | 34 |
|
39 | | - expect(log_event.type).to eql("log") |
40 | | - expect(log_event.level).to eql(level.to_sym) |
41 | | - expect(log_event.body).to eql("Hello World") |
42 | | - expect(log_event.attributes).to include(payload) |
| 35 | + expect(log_event[:level]).to eql(level) |
| 36 | + expect(log_event[:body]).to eql("Hello World") |
| 37 | + expect(log_event[:attributes]).to include({ user_id: { value: 123, type: "integer" } }) |
| 38 | + expect(log_event[:attributes]).to include({ action: { value: "create", type: "string" } }) |
43 | 39 | end |
44 | 40 |
|
45 | 41 | it "logs with template parameters" do |
46 | 42 | Sentry.logger.public_send(level, "Hello %s it is %s", ["Jane", "Monday"]) |
47 | 43 |
|
48 | | - expect(logs).to_not be_empty |
49 | | - |
50 | | - log_event = logs.last |
51 | | - log_hash = log_event.to_hash |
52 | | - |
53 | | - expect(log_event.type).to eql("log") |
54 | | - expect(log_event.level).to eql(level.to_sym) |
55 | | - expect(log_event.body).to eql("Hello %s it is %s") |
| 44 | + expect(sentry_logs).to_not be_empty |
56 | 45 |
|
57 | | - expect(log_hash[:body]).to eql("Hello Jane it is Monday") |
| 46 | + log_event = sentry_logs.last |
58 | 47 |
|
59 | | - attributes = log_hash[:attributes] |
60 | | - |
61 | | - expect(attributes["sentry.message.template"]).to eql({ value: "Hello %s it is %s", type: "string" }) |
62 | | - expect(attributes["sentry.message.parameters.0"]).to eql({ value: "Jane", type: "string" }) |
63 | | - expect(attributes["sentry.message.parameters.1"]).to eql({ value: "Monday", type: "string" }) |
| 48 | + expect(log_event[:level]).to eql(level) |
| 49 | + expect(log_event[:body]).to eql("Hello Jane it is Monday") |
| 50 | + expect(log_event[:attributes]["sentry.message.template"]).to eql({ value: "Hello %s it is %s", type: "string" }) |
| 51 | + expect(log_event[:attributes]["sentry.message.parameters.0"]).to eql({ value: "Jane", type: "string" }) |
| 52 | + expect(log_event[:attributes]["sentry.message.parameters.1"]).to eql({ value: "Monday", type: "string" }) |
64 | 53 | end |
65 | 54 |
|
66 | 55 | it "logs with template parameters and extra attributres" do |
67 | 56 | Sentry.logger.public_send(level, "Hello %s it is %s", ["Jane", "Monday"], extra: 312) |
68 | 57 |
|
69 | | - expect(logs).to_not be_empty |
70 | | - |
71 | | - log_event = logs.last |
72 | | - log_hash = log_event.to_hash |
73 | | - |
74 | | - expect(log_event.type).to eql("log") |
75 | | - expect(log_event.level).to eql(level.to_sym) |
76 | | - expect(log_event.body).to eql("Hello %s it is %s") |
| 58 | + expect(sentry_logs).to_not be_empty |
77 | 59 |
|
78 | | - expect(log_hash[:body]).to eql("Hello Jane it is Monday") |
| 60 | + log_event = sentry_logs.last |
79 | 61 |
|
80 | | - attributes = log_hash[:attributes] |
81 | | - |
82 | | - expect(attributes[:extra]).to eql({ value: 312, type: "integer" }) |
83 | | - expect(attributes["sentry.message.template"]).to eql({ value: "Hello %s it is %s", type: "string" }) |
84 | | - expect(attributes["sentry.message.parameters.0"]).to eql({ value: "Jane", type: "string" }) |
85 | | - expect(attributes["sentry.message.parameters.1"]).to eql({ value: "Monday", type: "string" }) |
| 62 | + expect(log_event[:level]).to eql(level) |
| 63 | + expect(log_event[:body]).to eql("Hello Jane it is Monday") |
| 64 | + expect(log_event[:attributes][:extra]).to eql({ value: 312, type: "integer" }) |
| 65 | + expect(log_event[:attributes]["sentry.message.template"]).to eql({ value: "Hello %s it is %s", type: "string" }) |
| 66 | + expect(log_event[:attributes]["sentry.message.parameters.0"]).to eql({ value: "Jane", type: "string" }) |
| 67 | + expect(log_event[:attributes]["sentry.message.parameters.1"]).to eql({ value: "Monday", type: "string" }) |
86 | 68 | end |
87 | 69 |
|
88 | 70 | it "logs with hash-based template parameters" do |
89 | 71 | Sentry.logger.public_send(level, "Hello %{name}, it is %{day}", name: "Jane", day: "Monday") |
90 | 72 |
|
91 | | - expect(logs).to_not be_empty |
92 | | - |
93 | | - log_event = logs.last |
94 | | - log_hash = log_event.to_hash |
95 | | - |
96 | | - expect(log_event.type).to eql("log") |
97 | | - expect(log_event.level).to eql(level.to_sym) |
98 | | - expect(log_event.body).to eql("Hello %{name}, it is %{day}") |
99 | | - |
100 | | - expect(log_hash[:body]).to eql("Hello Jane, it is Monday") |
| 73 | + expect(sentry_logs).to_not be_empty |
101 | 74 |
|
102 | | - attributes = log_hash[:attributes] |
| 75 | + log_event = sentry_logs.last |
103 | 76 |
|
104 | | - expect(attributes["sentry.message.template"]).to eql({ value: "Hello %{name}, it is %{day}", type: "string" }) |
105 | | - expect(attributes["sentry.message.parameters.name"]).to eql({ value: "Jane", type: "string" }) |
106 | | - expect(attributes["sentry.message.parameters.day"]).to eql({ value: "Monday", type: "string" }) |
| 77 | + expect(log_event[:level]).to eql(level) |
| 78 | + expect(log_event[:body]).to eql("Hello Jane, it is Monday") |
| 79 | + expect(log_event[:attributes]["sentry.message.template"]).to eql({ value: "Hello %{name}, it is %{day}", type: "string" }) |
| 80 | + expect(log_event[:attributes]["sentry.message.parameters.name"]).to eql({ value: "Jane", type: "string" }) |
| 81 | + expect(log_event[:attributes]["sentry.message.parameters.day"]).to eql({ value: "Monday", type: "string" }) |
107 | 82 | end |
108 | 83 |
|
109 | 84 | it "logs with hash-based template parameters and extra attributes" do |
110 | 85 | Sentry.logger.public_send(level, "Hello %{name}, it is %{day}", name: "Jane", day: "Monday", user_id: 123) |
111 | 86 |
|
112 | | - expect(logs).to_not be_empty |
113 | | - |
114 | | - log_event = logs.last |
115 | | - log_hash = log_event.to_hash |
116 | | - |
117 | | - expect(log_event.type).to eql("log") |
118 | | - expect(log_event.level).to eql(level.to_sym) |
119 | | - expect(log_event.body).to eql("Hello %{name}, it is %{day}") |
120 | | - |
121 | | - expect(log_hash[:body]).to eql("Hello Jane, it is Monday") |
| 87 | + expect(sentry_logs).to_not be_empty |
122 | 88 |
|
123 | | - attributes = log_hash[:attributes] |
| 89 | + log_event = sentry_logs.last |
124 | 90 |
|
125 | | - expect(attributes[:user_id]).to eql({ value: 123, type: "integer" }) |
126 | | - expect(attributes["sentry.message.template"]).to eql({ value: "Hello %{name}, it is %{day}", type: "string" }) |
127 | | - expect(attributes["sentry.message.parameters.name"]).to eql({ value: "Jane", type: "string" }) |
128 | | - expect(attributes["sentry.message.parameters.day"]).to eql({ value: "Monday", type: "string" }) |
| 91 | + expect(log_event[:level]).to eql(level) |
| 92 | + expect(log_event[:body]).to eql("Hello Jane, it is Monday") |
| 93 | + expect(log_event[:attributes][:user_id]).to eql({ value: 123, type: "integer" }) |
| 94 | + expect(log_event[:attributes]["sentry.message.template"]).to eql({ value: "Hello %{name}, it is %{day}", type: "string" }) |
| 95 | + expect(log_event[:attributes]["sentry.message.parameters.name"]).to eql({ value: "Jane", type: "string" }) |
| 96 | + expect(log_event[:attributes]["sentry.message.parameters.day"]).to eql({ value: "Monday", type: "string" }) |
129 | 97 | end |
130 | 98 | end |
131 | 99 | end |
|
0 commit comments