Class: Appsignal::Extension::Transaction

Inherits:
Object
  • Object
show all
Defined in:
ext/appsignal_extension.c

Instance Method Summary collapse

Instance Method Details

#completeObject



276
277
278
279
280
281
282
283
# File 'ext/appsignal_extension.c', line 276

static VALUE complete_transaction(VALUE self) {
  appsignal_transaction_t* transaction;

  Data_Get_Struct(self, appsignal_transaction_t, transaction);

  appsignal_complete_transaction(transaction);
  return Qnil;
}

#finish(gc_duration_ms) ⇒ Object



265
266
267
268
269
270
271
272
273
274
# File 'ext/appsignal_extension.c', line 265

static VALUE finish_transaction(VALUE self, VALUE gc_duration_ms) {
  appsignal_transaction_t* transaction;
  int sample;

  Check_Type(gc_duration_ms, T_FIXNUM);
  Data_Get_Struct(self, appsignal_transaction_t, transaction);

  sample = appsignal_finish_transaction(transaction, NUM2LONG(gc_duration_ms));
  return sample == 1 ? Qtrue : Qfalse;
}

#finish_event(name, title, body, body_format, gc_duration_ms) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'ext/appsignal_extension.c', line 85

static VALUE finish_event(VALUE self, VALUE name, VALUE title, VALUE body, VALUE body_format, VALUE gc_duration_ms) {
  appsignal_transaction_t* transaction;
  appsignal_data_t* body_data;
  int body_type;

  Check_Type(name, T_STRING);
  Check_Type(title, T_STRING);
  Check_Type(body_format, T_FIXNUM);

  Data_Get_Struct(self, appsignal_transaction_t, transaction);

  body_type = TYPE(body);
  if (body_type == T_STRING) {
    appsignal_finish_event(
        transaction,
        make_appsignal_string(name),
        make_appsignal_string(title),
        make_appsignal_string(body),
        FIX2INT(body_format),
        FIX2LONG(gc_duration_ms)
    );
  } else if (body_type == RUBY_T_DATA) {
    Data_Get_Struct(body, appsignal_data_t, body_data);
    appsignal_finish_event_data(
        transaction,
        make_appsignal_string(name),
        make_appsignal_string(title),
        body_data,
        FIX2INT(body_format),
        FIX2LONG(gc_duration_ms)
    );
  } else {
      rb_raise(rb_eTypeError, "body should be a String or Appsignal::Extension::Data");
  }

  return Qnil;
}

#record_event(name, title, body, body_format, duration, gc_duration_ms) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'ext/appsignal_extension.c', line 123

static VALUE record_event(VALUE self, VALUE name, VALUE title, VALUE body, VALUE body_format, VALUE duration, VALUE gc_duration_ms) {
  appsignal_transaction_t* transaction;
  appsignal_data_t* body_data;
  int body_type;
  int duration_type;

  Check_Type(name, T_STRING);
  Check_Type(title, T_STRING);
  duration_type = TYPE(duration);
  if (duration_type != T_FIXNUM && duration_type != T_BIGNUM) {
      rb_raise(rb_eTypeError, "duration should be an Integer");
  }
  Check_Type(body_format, T_FIXNUM);

  Data_Get_Struct(self, appsignal_transaction_t, transaction);

  body_type = TYPE(body);
  if (body_type == T_STRING) {
    appsignal_record_event(
        transaction,
        make_appsignal_string(name),
        make_appsignal_string(title),
        make_appsignal_string(body),
        FIX2INT(body_format),
        NUM2LONG(duration),
        NUM2LONG(gc_duration_ms)
    );
  } else if (body_type == RUBY_T_DATA) {
    Data_Get_Struct(body, appsignal_data_t, body_data);
    appsignal_record_event_data(
        transaction,
        make_appsignal_string(name),
        make_appsignal_string(title),
        body_data,
        FIX2INT(body_format),
        NUM2LONG(duration),
        NUM2LONG(gc_duration_ms)
    );
  } else {
      rb_raise(rb_eTypeError, "body should be a String or Appsignal::Extension::Data");
  }

  return Qnil;
}

#set_action(action) ⇒ Object



206
207
208
209
210
211
212
213
214
215
216
217
# File 'ext/appsignal_extension.c', line 206

static VALUE set_transaction_action(VALUE self, VALUE action) {
  appsignal_transaction_t* transaction;

  Check_Type(action, T_STRING);
  Data_Get_Struct(self, appsignal_transaction_t, transaction);

  appsignal_set_transaction_action(
      transaction,
      make_appsignal_string(action)
  );
  return Qnil;
}

#set_error(name, message, backtrace) ⇒ Object



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'ext/appsignal_extension.c', line 168

static VALUE set_transaction_error(VALUE self, VALUE name, VALUE message, VALUE backtrace) {
  appsignal_transaction_t* transaction;
  appsignal_data_t* backtrace_data;

  Check_Type(name, T_STRING);
  Check_Type(message, T_STRING);
  Check_Type(backtrace, RUBY_T_DATA);

  Data_Get_Struct(self, appsignal_transaction_t, transaction);
  Data_Get_Struct(backtrace, appsignal_data_t, backtrace_data);

  appsignal_set_transaction_error(
      transaction,
      make_appsignal_string(name),
      make_appsignal_string(message),
      backtrace_data
  );
  return Qnil;
}

#set_metadata(key, value) ⇒ Object



250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'ext/appsignal_extension.c', line 250

static VALUE set_transaction_metadata(VALUE self, VALUE key, VALUE value) {
  appsignal_transaction_t* transaction;

  Check_Type(key, T_STRING);
  Check_Type(value, T_STRING);
  Data_Get_Struct(self, appsignal_transaction_t, transaction);

  appsignal_set_transaction_metadata(
      transaction,
      make_appsignal_string(key),
      make_appsignal_string(value)
  );
  return Qnil;
}

#set_namespace(namespace) ⇒ Object



219
220
221
222
223
224
225
226
227
228
229
230
# File 'ext/appsignal_extension.c', line 219

static VALUE set_transaction_namespace(VALUE self, VALUE namespace) {
  appsignal_transaction_t* transaction;

  Check_Type(namespace, T_STRING);
  Data_Get_Struct(self, appsignal_transaction_t, transaction);

  appsignal_set_transaction_namespace(
      transaction,
      make_appsignal_string(namespace)
  );
  return Qnil;
}

#set_queue_start(queue_start) ⇒ Object



232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# File 'ext/appsignal_extension.c', line 232

static VALUE set_transaction_queue_start(VALUE self, VALUE queue_start) {
  appsignal_transaction_t* transaction;
  int queue_start_type;

  queue_start_type = TYPE(queue_start);
  if (queue_start_type != T_FIXNUM && queue_start_type != T_BIGNUM) {
      rb_raise(rb_eTypeError, "queue_start should be an Integer");
  }

  Data_Get_Struct(self, appsignal_transaction_t, transaction);

  appsignal_set_transaction_queue_start(
      transaction,
      NUM2LONG(queue_start)
  );
  return Qnil;
}

#set_sample_data(key, payload) ⇒ Object



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'ext/appsignal_extension.c', line 188

static VALUE set_transaction_sample_data(VALUE self, VALUE key, VALUE payload) {
  appsignal_transaction_t* transaction;
  appsignal_data_t* payload_data;

  Check_Type(key, T_STRING);
  Check_Type(payload, RUBY_T_DATA);

  Data_Get_Struct(self, appsignal_transaction_t, transaction);
  Data_Get_Struct(payload, appsignal_data_t, payload_data);

  appsignal_set_transaction_sample_data(
      transaction,
      make_appsignal_string(key),
      payload_data
  );
  return Qnil;
}

#start_event(gc_duration_ms) ⇒ Object

Transaction instance methods



73
74
75
76
77
78
79
80
81
82
83
# File 'ext/appsignal_extension.c', line 73

static VALUE start_event(VALUE self, VALUE gc_duration_ms) {
  appsignal_transaction_t* transaction;

  Check_Type(gc_duration_ms, T_FIXNUM);

  Data_Get_Struct(self, appsignal_transaction_t, transaction);

  appsignal_start_event(transaction, NUM2LONG(gc_duration_ms));

  return Qnil;
}

#to_jsonObject



285
286
287
288
289
290
291
292
293
294
295
296
297
298
# File 'ext/appsignal_extension.c', line 285

static VALUE transaction_to_json(VALUE self) {
  appsignal_transaction_t* transaction;
  appsignal_string_t json;

  Data_Get_Struct(self, appsignal_transaction_t, transaction);

  json = appsignal_transaction_to_json(transaction);

  if (json.len == 0) {
    return Qnil;
  } else {
    return make_ruby_string(json);
  }
}