Class: Appsignal::Extension::Span

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.root(namespace) ⇒ Object

Create a span



549
550
551
552
553
554
555
556
557
558
559
560
561
# File 'ext/appsignal_extension.c', line 549

static VALUE root_span_new(VALUE self, VALUE namespace) {
  appsignal_span_t* span;

  Check_Type(namespace, T_STRING);

  span = appsignal_create_root_span(make_appsignal_string(namespace));

  if (span) {
    return Data_Wrap_Struct(Span, NULL, appsignal_free_span, span);
  } else {
    return Qnil;
  }
}

Instance Method Details

#add_error(name, message, backtrace) ⇒ Object

Set span error



589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
# File 'ext/appsignal_extension.c', line 589

static VALUE add_span_error(VALUE self, VALUE name, VALUE message, VALUE backtrace) {
  appsignal_span_t* span;
  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_span_t, span);
  Data_Get_Struct(backtrace, appsignal_data_t, backtrace_data);

  appsignal_add_span_error(
      span,
      make_appsignal_string(name),
      make_appsignal_string(message),
      backtrace_data
  );
  return Qnil;
}

#childObject



563
564
565
566
567
568
569
570
571
572
573
574
575
576
# File 'ext/appsignal_extension.c', line 563

static VALUE child_span_new(VALUE self) {
  appsignal_span_t* parent;
  appsignal_span_t* span;

  Data_Get_Struct(self, appsignal_span_t, parent);

  span = appsignal_create_child_span(parent);

  if (span) {
    return Data_Wrap_Struct(Span, NULL, appsignal_free_span, span);
  } else {
    return Qnil;
  }
}

#closeObject

Close span



713
714
715
716
717
718
719
720
721
# File 'ext/appsignal_extension.c', line 713

static VALUE close_span(VALUE self) {
  appsignal_span_t* span;

  Data_Get_Struct(self, appsignal_span_t, span);

  appsignal_close_span(span);

  return Qnil;
}

#set_attribute_bool(key, value) ⇒ Object



665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
# File 'ext/appsignal_extension.c', line 665

static VALUE set_span_attribute_bool(VALUE self, VALUE key, VALUE value) {
  appsignal_span_t* span;

  Check_Type(key, T_STRING);

  Data_Get_Struct(self, appsignal_span_t, span);

  appsignal_set_span_attribute_bool(
    span,
    make_appsignal_string(key),
    RTEST(value)
  );

  return Qnil;
}

#set_attribute_double(key, value) ⇒ Object



681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
# File 'ext/appsignal_extension.c', line 681

static VALUE set_span_attribute_double(VALUE self, VALUE key, VALUE value) {
  appsignal_span_t* span;

  Check_Type(key, T_STRING);
  Check_Type(value, T_FLOAT);

  Data_Get_Struct(self, appsignal_span_t, span);

  appsignal_set_span_attribute_double(
    span,
    make_appsignal_string(key),
    NUM2DBL(value)
  );

  return Qnil;
}

#set_attribute_int(key, value) ⇒ Object



644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
# File 'ext/appsignal_extension.c', line 644

static VALUE set_span_attribute_int(VALUE self, VALUE key, VALUE value) {
  appsignal_span_t* span;
  VALUE value_type = TYPE(value);

  Check_Type(key, T_STRING);

  if (value_type != T_FIXNUM && value_type != T_BIGNUM) {
    rb_raise(rb_eTypeError, "wrong argument type %s (expected Integer)", rb_obj_classname(value));
  }

  Data_Get_Struct(self, appsignal_span_t, span);

  appsignal_set_span_attribute_int(
    span,
    make_appsignal_string(key),
    NUM2LONG(value)
  );

  return Qnil;
}

#set_attribute_string(key, value) ⇒ Object

Set attributes on a span



627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
# File 'ext/appsignal_extension.c', line 627

static VALUE set_span_attribute_string(VALUE self, VALUE key, VALUE value) {
  appsignal_span_t* span;

  Check_Type(key, T_STRING);
  Check_Type(value, T_STRING);

  Data_Get_Struct(self, appsignal_span_t, span);

  appsignal_set_span_attribute_string(
    span,
    make_appsignal_string(key),
    make_appsignal_string(value)
  );

  return Qnil;
}

#set_name(name) ⇒ Object

Span name and namespace



578
579
580
581
582
583
584
585
586
587
# File 'ext/appsignal_extension.c', line 578

static VALUE set_span_name(VALUE self, VALUE name) {
  appsignal_span_t* span;

  Check_Type(name, T_STRING);

  Data_Get_Struct(self, appsignal_span_t, span);

  appsignal_set_span_name(span, make_appsignal_string(name));
  return Qnil;
}

#set_sample_data(key, payload) ⇒ Object

Set span sample data



609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
# File 'ext/appsignal_extension.c', line 609

static VALUE set_span_sample_data(VALUE self, VALUE key, VALUE payload) {
  appsignal_span_t* span;
  appsignal_data_t* payload_data;

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

  Data_Get_Struct(self, appsignal_span_t, span);
  Data_Get_Struct(payload, appsignal_data_t, payload_data);

  appsignal_set_span_sample_data(
      span,
      make_appsignal_string(key),
      payload_data
  );
  return Qnil;
}

#to_jsonObject

Span to json



698
699
700
701
702
703
704
705
706
707
708
709
710
711
# File 'ext/appsignal_extension.c', line 698

static VALUE span_to_json(VALUE self) {
  appsignal_span_t* span;
  appsignal_string_t json;

  Data_Get_Struct(self, appsignal_span_t, span);

  json = appsignal_span_to_json(span);

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