How to use the opentelemetry-sdk.src.opentelemetry.sdk.trace.export.SpanExporter function in opentelemetry-sdk

To help you get started, we’ve selected a few opentelemetry-sdk 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 open-telemetry / opentelemetry-python / opentelemetry-sdk / src / opentelemetry / sdk / trace / export / in_memory_span_exporter.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.

import threading
import typing

from .. import Span
from . import SpanExporter, SpanExportResult


class InMemorySpanExporter(SpanExporter):
    """Implementation of :class:`.SpanExporter` that stores spans in memory.

    This class can be used for testing purposes. It stores the exported spans
    in a list in memory that can be retrieved using the
    :func:`.get_finished_spans` method.
    """

    def __init__(self):
        self._finished_spans = []
        self._stopped = False
        self._lock = threading.Lock()

    def clear(self):
        """Clear list of collected spans."""
        with self._lock:
            self._finished_spans.clear()

opentelemetry-sdk

OpenTelemetry Python SDK

Apache-2.0
Latest version published 14 days ago

Package Health Score

97 / 100
Full package analysis