How to use the opencensus.trace.status.Status function in opencensus

To help you get started, we’ve selected a few opencensus examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github census-instrumentation / opencensus-python / tests / unit / trace / ext / flask / test_flask_middleware.py View on Github external
def test_teardown_include_exception(self):
        mock_exporter = mock.MagicMock()
        app = self.create_app()
        flask_middleware.FlaskMiddleware(app=app, exporter=mock_exporter)
        response = app.test_client().get('/error')

        self.assertEqual(response.status_code, 500)

        exported_spandata = mock_exporter.export.call_args[0][0][0]
        self.assertIsInstance(exported_spandata, span_data.SpanData)
        self.assertIsInstance(exported_spandata.status, status.Status)
        self.assertEqual(exported_spandata.status.code, code_pb2.UNKNOWN)
        self.assertEqual(exported_spandata.status.message, 'error')
github census-instrumentation / opencensus-python / tests / unit / trace / exporters / test_jaeger_exporter.py View on Github external
span_id=span_id,
                type=link.Type.CHILD_LINKED_SPAN,
                attributes=link_attributes),
            link.Link(
                trace_id=trace_id,
                span_id=span_id,
                type=link.Type.PARENT_LINKED_SPAN,
                attributes=link_attributes),
            link.Link(
                trace_id=trace_id,
                span_id=span_id,
                type=link.Type.TYPE_UNSPECIFIED,
                attributes=link_attributes)
        ]

        span_status = status.Status(code=200, message='success')

        start_time = '2017-08-15T18:02:26.071158Z'
        end_time = '2017-08-15T18:02:36.071158Z'

        span_datas = [
            span_data.SpanData(
                name='test1',
                context=span_context.SpanContext(trace_id=trace_id),
                span_id=span_id,
                parent_span_id=parent_span_id,
                attributes=span_attributes,
                start_time=start_time,
                end_time=end_time,
                child_span_count=0,
                stack_trace=None,
                time_events=time_events,
github census-instrumentation / opencensus-python / tests / unit / trace / test_span_data.py View on Github external
def test_format_legacy_trace_json(self):
        trace_id = '2dd43a1d6b2549c6bc2a1a54c2fc0b05'
        span_data = span_data_module.SpanData(
            name='root',
            context=span_context.SpanContext(
                trace_id=trace_id,
                span_id='6e0c63257de34c92'
            ),
            span_id='6e0c63257de34c92',
            parent_span_id='6e0c63257de34c93',
            attributes={'key1': 'value1'},
            start_time=utils.to_iso_str(),
            end_time=utils.to_iso_str(),
            stack_trace=stack_trace.StackTrace(stack_trace_hash_id='111'),
            links=[link.Link('1111', span_id='6e0c63257de34c92')],
            status=status.Status(code=0, message='pok'),
            annotations=[
                time_event.Annotation(
                    timestamp=datetime.datetime(1970, 1, 1),
                    description='description'
                )
            ],
            message_events=[
                time_event.MessageEvent(
                    timestamp=datetime.datetime(1970, 1, 1),
                    id=0,
                )
            ],
            same_process_as_parent_span=False,
            child_span_count=0,
            span_kind=0,
        )
github census-instrumentation / opencensus-python / contrib / opencensus-ext-pymongo / opencensus / ext / pymongo / trace.py View on Github external
def _stop(self, code, message='', details=None):
        span = self.tracer.current_span()
        status = status_module.Status(
            code=code, message=message, details=details
        )
        span.set_status(status)
        self.tracer.end_span()
github census-instrumentation / opencensus-python / opencensus / trace / exceptions_status.py View on Github external
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from google.rpc import code_pb2

from opencensus.trace.status import Status

CANCELLED = Status(code_pb2.CANCELLED)
INVALID_URL = Status(code_pb2.INVALID_ARGUMENT, message='invalid URL')
TIMEOUT = Status(code_pb2.DEADLINE_EXCEEDED, message='request timed out')


def unknown(exception):
    return Status.from_exception(exception)
github census-instrumentation / opencensus-python / opencensus / trace / exceptions_status.py View on Github external
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from google.rpc import code_pb2

from opencensus.trace.status import Status

CANCELLED = Status(code_pb2.CANCELLED)
INVALID_URL = Status(code_pb2.INVALID_ARGUMENT, message='invalid URL')
TIMEOUT = Status(code_pb2.DEADLINE_EXCEEDED, message='request timed out')


def unknown(exception):
    return Status.from_exception(exception)
github census-instrumentation / opencensus-python / contrib / opencensus-ext-flask / opencensus / ext / flask / flask_middleware.py View on Github external
def _teardown_request(self, exception):
        # Do not trace if the url is blacklisted
        if utils.disable_tracing_url(flask.request.url, self.blacklist_paths):
            return

        try:
            tracer = execution_context.get_opencensus_tracer()

            if exception is not None:
                span = execution_context.get_current_span()
                if span is not None:
                    span.status = status.Status(
                        code=code_pb2.UNKNOWN,
                        message=str(exception)
                    )
                    # try attaching the stack trace to the span, only populated
                    # if the app has 'PROPAGATE_EXCEPTIONS', 'DEBUG', or
                    # 'TESTING' enabled
                    exc_type, _, exc_traceback = sys.exc_info()
                    if exc_traceback is not None:
                        span.stack_trace = (
                            stack_trace.StackTrace.from_traceback(
                                exc_traceback
                            )
                        )

            tracer.end_span()
            tracer.finish()
github census-instrumentation / opencensus-python / opencensus / trace / span.py View on Github external
else:
            self.annotations = BoundedList.from_seq(MAX_NUM_LINKS, annotations)

        if message_events is None:
            self.message_events = BoundedList(MAX_NUM_MESSAGE_EVENTS)
        else:
            self.message_events = BoundedList.from_seq(
                MAX_NUM_LINKS, message_events)

        if links is None:
            self.links = BoundedList(MAX_NUM_LINKS)
        else:
            self.links = BoundedList.from_seq(MAX_NUM_LINKS, links)

        if status is None:
            self.status = status_module.Status.as_ok()
        else:
            self.status = status

        self.span_id = span_id
        self.stack_trace = stack_trace
        self.same_process_as_parent_span = same_process_as_parent_span
        self._child_spans = []
        self.context_tracer = context_tracer
        self.span_kind = span_kind
        for callback in Span._on_create_callbacks:
            callback(self)
github census-instrumentation / opencensus-python / contrib / opencensus-ext-grpc / opencensus / ext / grpc / server_interceptor.py View on Github external
def _add_exc_info(span):
    exc_type, exc_value, tb = sys.exc_info()
    span.add_attribute(
        attributes_helper.COMMON_ATTRIBUTES.get(
            ATTRIBUTE_ERROR_MESSAGE),
        str(exc_value)
    )
    span.stack_trace = stack_trace.StackTrace.from_traceback(tb)
    span.status = status.Status(
        code=code_pb2.UNKNOWN,
        message=str(exc_value)
    )