Class: Appsignal::Extension::Transaction

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

Instance Method Summary collapse

Instance Method Details

#completeObject



323
324
325
326
327
328
329
330
# File 'ext/appsignal_extension.c', line 323

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

  TypedData_Get_Struct(self, appsignal_transaction_t, &transaction_data_type, transaction);

  appsignal_complete_transaction(transaction);
  return Qnil;
}

#duplicate(new_transaction_id) ⇒ Object



300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
# File 'ext/appsignal_extension.c', line 300

static VALUE duplicate_transaction(VALUE self, VALUE new_transaction_id) {
  appsignal_transaction_t* transaction;
  appsignal_transaction_t* duplicate_transaction;

  Check_Type(new_transaction_id, T_STRING);
  TypedData_Get_Struct(self, appsignal_transaction_t, &transaction_data_type, transaction);

  duplicate_transaction = appsignal_duplicate_transaction(
      transaction,
      make_appsignal_string(new_transaction_id)
  );

  if (duplicate_transaction) {
      return TypedData_Wrap_Struct(
          Transaction,
          &transaction_data_type,
          duplicate_transaction
      );
  } else {
      return Qnil;
  }
}

#finish(gc_duration_ms) ⇒ Object



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

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

  Check_Type(gc_duration_ms, T_FIXNUM);
  TypedData_Get_Struct(self, appsignal_transaction_t, &transaction_data_type, 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



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'ext/appsignal_extension.c', line 109

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);

  TypedData_Get_Struct(self, appsignal_transaction_t, &transaction_data_type, 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 == T_DATA) {
    TypedData_Get_Struct(body, appsignal_data_t, &data_data_type, 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



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'ext/appsignal_extension.c', line 147

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);

  TypedData_Get_Struct(self, appsignal_transaction_t, &transaction_data_type, 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 == T_DATA) {
    TypedData_Get_Struct(body, appsignal_data_t, &data_data_type, 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



230
231
232
233
234
235
236
237
238
239
240
241
# File 'ext/appsignal_extension.c', line 230

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

  Check_Type(action, T_STRING);
  TypedData_Get_Struct(self, appsignal_transaction_t, &transaction_data_type, transaction);

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

#set_error(name, message, backtrace) ⇒ Object



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'ext/appsignal_extension.c', line 192

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);

  backtrace_data = rb_check_typeddata(backtrace, &data_data_type);

  TypedData_Get_Struct(self, appsignal_transaction_t, &transaction_data_type, transaction);

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

#set_metadata(key, value) ⇒ Object



274
275
276
277
278
279
280
281
282
283
284
285
286
287
# File 'ext/appsignal_extension.c', line 274

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);
  TypedData_Get_Struct(self, appsignal_transaction_t, &transaction_data_type, transaction);

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

#set_namespace(namespace) ⇒ Object



243
244
245
246
247
248
249
250
251
252
253
254
# File 'ext/appsignal_extension.c', line 243

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

  Check_Type(namespace, T_STRING);
  TypedData_Get_Struct(self, appsignal_transaction_t, &transaction_data_type, transaction);

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

#set_queue_start(queue_start) ⇒ Object



256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'ext/appsignal_extension.c', line 256

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");
  }

  TypedData_Get_Struct(self, appsignal_transaction_t, &transaction_data_type, transaction);

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

#set_sample_data(key, payload) ⇒ Object



212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'ext/appsignal_extension.c', line 212

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);

  payload_data = rb_check_typeddata(payload, &data_data_type);

  TypedData_Get_Struct(self, appsignal_transaction_t, &transaction_data_type, transaction);

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

#start_event(gc_duration_ms) ⇒ Object

Transaction instance methods



97
98
99
100
101
102
103
104
105
106
107
# File 'ext/appsignal_extension.c', line 97

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

  Check_Type(gc_duration_ms, T_FIXNUM);

  TypedData_Get_Struct(self, appsignal_transaction_t, &transaction_data_type, transaction);

  appsignal_start_event(transaction, NUM2LONG(gc_duration_ms));

  return Qnil;
}

#to_jsonObject



332
333
334
335
336
337
338
339
340
341
342
343
344
345
# File 'ext/appsignal_extension.c', line 332

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

  TypedData_Get_Struct(self, appsignal_transaction_t, &transaction_data_type, transaction);

  json = appsignal_transaction_to_json(transaction);

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