Skip to content

Commit 4290ac7

Browse files
authored
Add entry point for x-cloud-trace-context propagator (#183)
1 parent 9b0c251 commit 4290ac7

File tree

5 files changed

+84
-3
lines changed

5 files changed

+84
-3
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
OpenTelemetry Cloud Trace Propagator
2+
==================================
3+
4+
.. image:: https://badge.fury.io/py/opentelemetry-propagator-gcp.svg
5+
:target: https://badge.fury.io/py/opentelemetry-propagator-gcp
6+
7+
.. automodule:: opentelemetry.propagators.cloud_trace_propagator
8+
:members:
9+
:undoc-members:
10+
:show-inheritance:
11+
:noindex:

docs/index.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ To install the GCP trace propagator:
4949
:maxdepth: 1
5050
:caption: Exporters
5151
:name: exporters
52+
:glob:
5253

53-
cloud_monitoring/cloud_monitoring
54-
cloud_trace/cloud_trace
54+
cloud_monitoring/**
55+
cloud_trace/**
5556

5657

5758
.. toctree::

opentelemetry-propagator-gcp/setup.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,7 @@ where = src
3232

3333
[options.extras_require]
3434
test =
35+
36+
[options.entry_points]
37+
opentelemetry_propagator =
38+
gcp_trace = opentelemetry.propagators.cloud_trace_propagator:CloudTraceFormatPropagator

opentelemetry-propagator-gcp/src/opentelemetry/propagators/cloud_trace_propagator/__init__.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,38 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
#
14+
15+
"""Cloud Trace Span Propagator for X-Cloud-Trace-Context format.
16+
17+
Usage
18+
-----
19+
20+
.. code-block:: python
21+
22+
from opentelemetry.propagate import set_global_textmap
23+
from opentelemetry.propagators.cloud_trace_propagator import (
24+
CloudTraceFormatPropagator,
25+
)
26+
27+
# Set the X-Cloud-Trace-Context header
28+
set_global_textmap(CloudTraceFormatPropagator())
29+
30+
Auto-instrumentation
31+
--------------------
32+
33+
This exporter can also be used with the :envvar:`OTEL_PROPAGATORS` environment variable as
34+
``OTEL_PROPAGATORS=gcp_trace``.
35+
36+
This also works with `OpenTelemetry auto-instrumentation
37+
<https://opentelemetry.io/docs/instrumentation/python/automatic/>`_:
38+
39+
.. code-block:: sh
40+
41+
opentelemetry-instrument --propagator gcp_trace <command> <args>
42+
43+
API
44+
---
45+
"""
1546

1647
import re
1748
import typing
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright 2022 Google LLC
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+
# https://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 unittest import TestCase
16+
from unittest.mock import patch
17+
18+
from opentelemetry.environment_variables import OTEL_PROPAGATORS
19+
from opentelemetry.propagators.cloud_trace_propagator import (
20+
CloudTraceFormatPropagator,
21+
)
22+
23+
24+
class TestCloudTracePropagatorAutoInstrument(TestCase):
25+
@patch.dict("os.environ", {OTEL_PROPAGATORS: "gcp_trace"})
26+
def test_loads_cloud_trace_propagator(self):
27+
# This test is a bit fragile as the propagator entry points are loaded on the first
28+
# import of opentelemetry.propagate and saved in a global variable. If another tests
29+
# imports that before this one, it can fail.
30+
# pylint: disable=import-outside-toplevel
31+
from opentelemetry.propagate import propagators
32+
33+
self.assertEqual(len(propagators), 1)
34+
self.assertIsInstance(propagators[0], CloudTraceFormatPropagator)

0 commit comments

Comments
 (0)