コード例 #1
0
def test_not_sampled():

    segment = DummySegment()
    subsegment = DummySubsegment(segment)

    assert not segment.sampled
    assert not subsegment.sampled
コード例 #2
0
def test_dummy_segment_trace_id():
    segment = DummySegment()

    assert segment.trace_id != 'dummy'
    assert '-' in segment.trace_id
    # checking version of trace id
    assert segment.trace_id[:1] == '1'
コード例 #3
0
 def wrapper(self, *args, **kargs):
     if type(self.context).__name__ == 'AsyncContext':
         return func(self, *args, **kargs)
     segment = DummySegment()
     self.context.set_trace_entity(segment)
     result = func(self, *args, **kargs)
     self.context.clear_trace_entities()
     return result
コード例 #4
0
def current_segment():
    try:
        segment = xray_recorder.current_segment()
        if segment:
            return segment
    except SegmentNotFoundException:
        pass

    return DummySegment()
コード例 #5
0
def test_structure_intact():
    segment = DummySegment()
    subsegment = DummySubsegment(segment)
    subsegment2 = DummySubsegment(segment)
    subsegment.add_subsegment(subsegment2)
    segment.add_subsegment(subsegment)

    assert segment.subsegments[0] is subsegment
    assert subsegment.subsegments[0] is subsegment2

    subsegment2.close()
    subsegment.close()
    segment.close()
    assert segment.ready_to_send()
コード例 #6
0
ファイル: mixins.py プロジェクト: crazytruth/incendiary
    async def __call__(self, wrapped, instance, args, kwargs):

        if is_already_recording(wrapped):
            # The wrapped function is already decorated, the subsegment will be created later,
            # just return the result
            return await wrapped(*args, **kwargs)

        func_name = self.name
        if not func_name:
            func_name = wrapped.__name__

        if not global_sdk_config.sdk_enabled() or self.instance.app is None:
            try:
                segment = self.recorder.current_segment()
            except SegmentNotFoundException:
                segment = DummySegment(func_name)
                self.recorder.context.put_segment(segment)
            finally:
                if segment is None:
                    error_logger.warning(
                        CAPTURE_WARNING.format(name=func_name))
                elif (hasattr(self.instance.app, "initialized_plugins")
                      and "incendiary"
                      not in self.instance.app.initialized_plugins):
                    error_logger.warning(
                        CAPTURE_WARNING.format(name=func_name))

        try:
            return await self.recorder.record_subsegment_async(
                wrapped,
                instance,
                args,
                kwargs,
                name=func_name,
                namespace="local",
                meta_processor=None,
            )
        except exceptions.AlreadyEndedException:
            return await wrapped(*args, **kwargs)
コード例 #7
0
def test_invalid_entity_name():
    segment = DummySegment('DummySegment() Test?')
    subsegment = DummySubsegment(segment, 'Dummy*Sub!segment$')

    assert segment.name == 'DummySegment Test'
    assert subsegment.name == 'DummySubsegment'
コード例 #8
0
def test_no_ops():
    segment = DummySegment()
    segment.put_metadata('key', 'value')
    segment.put_annotation('key', 'value')
    segment.put_http_meta(http.URL, 'url')
    segment.set_user('user')

    assert not segment.metadata
    assert not segment.annotations
    assert not segment.http
    assert not segment.user

    subsegment = DummySubsegment(segment)
    subsegment.put_metadata('key', 'value')
    subsegment.put_annotation('key', 'value')
    subsegment.put_http_meta(http.URL, 'url')
    subsegment.set_aws({'key': 'value'})
    subsegment.set_sql({'key': 'value'})

    assert not subsegment.metadata
    assert not subsegment.annotations
    assert not subsegment.http
    assert not subsegment.aws
    assert not subsegment.sql

    assert not segment.serialize()
    assert not subsegment.serialize()