| 1 |
# Copyright The OpenTracing Authors |
| 2 |
# |
| 3 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
# you may not use this file except in compliance with the License. |
| 5 |
# You may obtain a copy of the License at |
| 6 |
# |
| 7 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
# |
| 9 |
# Unless required by applicable law or agreed to in writing, software |
| 10 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
# See the License for the specific language governing permissions and |
| 13 |
# limitations under the License. |
| 14 |
|
| 15 |
from __future__ import absolute_import |
| 16 |
|
| 17 |
|
| 18 |
class UnsupportedFormatException(Exception): |
| 19 |
"""UnsupportedFormatException should be used when the provided format |
| 20 |
value is unknown or disallowed by the :class:`Tracer`. |
| 21 |
|
| 22 |
See :meth:`Tracer.inject()` and :meth:`Tracer.extract()`. |
| 23 |
""" |
| 24 |
pass |
| 25 |
|
| 26 |
|
| 27 |
class InvalidCarrierException(Exception): |
| 28 |
"""InvalidCarrierException should be used when the provided carrier |
| 29 |
instance does not match what the `format` argument requires. |
| 30 |
|
| 31 |
See :meth:`Tracer.inject()` and :meth:`Tracer.extract()`. |
| 32 |
""" |
| 33 |
pass |
| 34 |
|
| 35 |
|
| 36 |
class SpanContextCorruptedException(Exception): |
| 37 |
"""SpanContextCorruptedException should be used when the underlying |
| 38 |
:class:`SpanContext` state is seemingly present but not well-formed. |
| 39 |
|
| 40 |
See :meth:`Tracer.inject()` and :meth:`Tracer.extract()`. |
| 41 |
""" |
| 42 |
pass |
| 43 |
|
| 44 |
|
| 45 |
class Format(object): |
| 46 |
"""A namespace for builtin carrier formats. |
| 47 |
|
| 48 |
These static constants are intended for use in the :meth:`Tracer.inject()` |
| 49 |
and :meth:`Tracer.extract()` methods. E.g.:: |
| 50 |
|
| 51 |
tracer.inject(span.context, Format.BINARY, binary_carrier) |
| 52 |
|
| 53 |
""" |
| 54 |
|
| 55 |
BINARY = 'binary' |
| 56 |
""" |
| 57 |
The BINARY format represents SpanContexts in an opaque bytearray carrier. |
| 58 |
|
| 59 |
For both :meth:`Tracer.inject()` and :meth:`Tracer.extract()` the carrier |
| 60 |
should be a bytearray instance. :meth:`Tracer.inject()` must append to the |
| 61 |
bytearray carrier (rather than replace its contents). |
| 62 |
""" |
| 63 |
|
| 64 |
TEXT_MAP = 'text_map' |
| 65 |
""" |
| 66 |
The TEXT_MAP format represents :class:`SpanContext`\\ s in a python |
| 67 |
``dict`` mapping from strings to strings. |
| 68 |
|
| 69 |
Both the keys and the values have unrestricted character sets (unlike the |
| 70 |
HTTP_HEADERS format). |
| 71 |
|
| 72 |
NOTE: The TEXT_MAP carrier ``dict`` may contain unrelated data (e.g., |
| 73 |
arbitrary gRPC metadata). As such, the :class:`Tracer` implementation |
| 74 |
should use a prefix or other convention to distinguish tracer-specific |
| 75 |
key:value pairs. |
| 76 |
""" |
| 77 |
|
| 78 |
HTTP_HEADERS = 'http_headers' |
| 79 |
""" |
| 80 |
The HTTP_HEADERS format represents :class:`SpanContext`\\ s in a python |
| 81 |
``dict`` mapping from character-restricted strings to strings. |
| 82 |
|
| 83 |
Keys and values in the HTTP_HEADERS carrier must be suitable for use as |
| 84 |
HTTP headers (without modification or further escaping). That is, the |
| 85 |
keys have a greatly restricted character set, casing for the keys may not |
| 86 |
be preserved by various intermediaries, and the values should be |
| 87 |
URL-escaped. |
| 88 |
|
| 89 |
NOTE: The HTTP_HEADERS carrier ``dict`` may contain unrelated data (e.g., |
| 90 |
arbitrary gRPC metadata). As such, the :class:`Tracer` implementation |
| 91 |
should use a prefix or other convention to distinguish tracer-specific |
| 92 |
key:value pairs. |
| 93 |
""" |