Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add entry point for x-cloud-trace-context propagator #183

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/cloud_trace/cloud_trace_propagator.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
OpenTelemetry Cloud Trace Propagator
==================================

.. image:: https://badge.fury.io/py/opentelemetry-propagator-gcp.svg
:target: https://badge.fury.io/py/opentelemetry-propagator-gcp

.. automodule:: opentelemetry.propagators.cloud_trace_propagator
:members:
:undoc-members:
:show-inheritance:
:noindex:
5 changes: 3 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ To install the GCP trace propagator:
:maxdepth: 1
:caption: Exporters
:name: exporters
:glob:

cloud_monitoring/cloud_monitoring
cloud_trace/cloud_trace
cloud_monitoring/**
cloud_trace/**


.. toctree::
Expand Down
4 changes: 4 additions & 0 deletions opentelemetry-propagator-gcp/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ where = src

[options.extras_require]
test =

[options.entry_points]
opentelemetry_propagator =
gcp_trace = opentelemetry.propagators.cloud_trace_propagator:CloudTraceFormatPropagator
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,38 @@
# 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.
#

"""Cloud Trace Span Propagator for X-Cloud-Trace-Context format.

Usage
-----

.. code-block:: python

from opentelemetry.propagate import set_global_textmap
from opentelemetry.propagators.cloud_trace_propagator import (
CloudTraceFormatPropagator,
)

# Set the X-Cloud-Trace-Context header
set_global_textmap(CloudTraceFormatPropagator())

Auto-instrumentation
--------------------

This exporter can also be used with the :envvar:`OTEL_PROPAGATORS` environment variable as
``OTEL_PROPAGATORS=gcp_trace``.

This also works with `OpenTelemetry auto-instrumentation
<https://opentelemetry.io/docs/instrumentation/python/automatic/>`_:

.. code-block:: sh

opentelemetry-instrument --propagator gcp_trace <command> <args>

API
---
"""

import re
import typing
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://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 unittest import TestCase
from unittest.mock import patch

from opentelemetry.environment_variables import OTEL_PROPAGATORS
from opentelemetry.propagators.cloud_trace_propagator import (
CloudTraceFormatPropagator,
)


class TestCloudTracePropagatorAutoInstrument(TestCase):
@patch.dict("os.environ", {OTEL_PROPAGATORS: "gcp_trace"})
def test_loads_cloud_trace_propagator(self):
# This test is a bit fragile as the propagator entry points are loaded on the first
# import of opentelemetry.propagate and saved in a global variable. If another tests
# imports that before this one, it can fail.
# pylint: disable=import-outside-toplevel
from opentelemetry.propagate import propagators

self.assertEqual(len(propagators), 1)
self.assertIsInstance(propagators[0], CloudTraceFormatPropagator)