Skip to content

Commit

Permalink
Add entry point for x-cloud-trace-context propagator
Browse files Browse the repository at this point in the history
  • Loading branch information
aabmass committed Apr 21, 2022
1 parent 9b0c251 commit 8be3ade
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 3 deletions.
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,33 @@
# 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,
)


# 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.
class TestCloudTracePropagatorAutoInstrument(TestCase):
@patch.dict("os.environ", {OTEL_PROPAGATORS: "gcp_trace"})
def test_loads_cloud_trace_propagator(self):
from opentelemetry.propagate import propagators

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

0 comments on commit 8be3ade

Please sign in to comment.