Skip to content

Commit 999b1b5

Browse files
committed
Add some docs and hook it into the system
Still not building content
1 parent 17947c5 commit 999b1b5

File tree

7 files changed

+117
-7
lines changed

7 files changed

+117
-7
lines changed

docs/conf.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,21 @@
2828

2929
exp = "../exporter"
3030
exp_dirs = [
31-
os.path.abspath("/".join(["../exporter", f, "src"]))
31+
os.path.abspath("/".join([exp, f, "src"]))
3232
for f in listdir(exp)
3333
if isdir(join(exp, f))
3434
]
3535

3636
instr = "../instrumentation"
3737
instr_dirs = [
38-
os.path.abspath("/".join(["../instrumentation", f, "src"]))
38+
os.path.abspath("/".join([instr, f, "src"]))
3939
for f in listdir(instr)
40-
if isdir(join(instr, f))
40+
if isdir(join(instr, f)) and f != "opentelemetry-instrumentation-boto"
4141
]
4242

4343
instr_genai = "../instrumentation-genai"
4444
instr_genai_dirs = [
45-
os.path.abspath("/".join(["../instrumentation-genai", f, "src"]))
45+
os.path.abspath("/".join([instr_genai, f, "src"]))
4646
for f in listdir(instr_genai)
4747
if isdir(join(instr_genai, f))
4848
]
@@ -56,24 +56,32 @@
5656

5757
sdk_ext = "../sdk-extension"
5858
sdk_ext_dirs = [
59-
os.path.abspath("/".join(["../sdk-extension", f, "src"]))
59+
os.path.abspath("/".join([sdk_ext, f, "src"]))
6060
for f in listdir(sdk_ext)
6161
if isdir(join(sdk_ext, f))
6262
]
6363

6464
resource = "../resource"
6565
resource_dirs = [
66-
os.path.abspath("/".join(["../resource", f, "src"]))
66+
os.path.abspath("/".join([resource, f, "src"]))
6767
for f in listdir(resource)
6868
if isdir(join(resource, f))
6969
]
70+
71+
opamp = "../opamp"
72+
opamp_dirs = [
73+
os.path.abspath("/".join([opamp, f, "src"]))
74+
for f in listdir(opamp)
75+
if isdir(join(opamp, f))
76+
]
7077
sys.path[:0] = (
7178
exp_dirs
7279
+ instr_dirs
7380
+ instr_genai_dirs
7481
+ sdk_ext_dirs
7582
+ prop_dirs
7683
+ resource_dirs
84+
+ opamp_dirs
7785
)
7886

7987
# -- Project information -----------------------------------------------------
@@ -115,7 +123,7 @@
115123
"https://opentracing-python.readthedocs.io/en/latest/",
116124
None,
117125
),
118-
"aiohttp": ("https://aiohttp.readthedocs.io/en/stable/", None),
126+
"aiohttp": ("https://docs.aiohttp.org/en/stable/", None),
119127
"wrapt": ("https://wrapt.readthedocs.io/en/latest/", None),
120128
"pymongo": ("https://pymongo.readthedocs.io/en/stable/", None),
121129
"opentelemetry": (

docs/index.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,14 @@ install <https://pip.pypa.io/en/stable/reference/pip_install/#editable-installs>
103103

104104
resource/**
105105

106+
.. toctree::
107+
:maxdepth: 2
108+
:caption: OpAMP
109+
:name: OpAMP
110+
:glob:
111+
112+
opamp/**
113+
106114
Indices and tables
107115
------------------
108116

docs/opamp/client.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
OpenTelemetry Python - OpAMP Client
2+
===================================
3+
4+
.. automodule:: opentelemetry._opamp
5+
:members: agent, client
6+
:undoc-members:
7+
:show-inheritance:
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
graft src
2+
graft tests
3+
global-exclude *.pyc
4+
global-exclude *.pyo
5+
global-exclude __pycache__/*
6+
include CHANGELOG.md
7+
include MANIFEST.in
8+
include README.rst
9+
include LICENSE

opamp/opentelemetry-opamp-client/README.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Installation
1414
pip install opentelemetry-opamp-client
1515

1616

17+
This package provides an HTTP OpAMP client than can be used by OpenTelemetry distributions to provide remote config.
18+
1719
References
1820
----------
1921
* `OpenTelemetry OpAMP Client <https://opentelemetry-python-contrib.readthedocs.io/en/latest/opamp/client/client.html>`_

opamp/opentelemetry-opamp-client/src/opentelemetry/_opamp/agent.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,78 @@
2727
logger = logging.getLogger(__name__)
2828

2929

30+
"""
31+
OpenTelemetry Python - OpAMP client
32+
-----------------------------------
33+
34+
This package provides a bunch of classes that can be used by OpenTelemetry distributions implementors
35+
to implement remote config support via the OpAMP protocol.
36+
37+
The client implements the following capabilities:
38+
- ReportsStatus
39+
- ReportsHeartbeat
40+
- AcceptsRemoteConfig
41+
- ReportsRemoteConfig
42+
43+
These capabilities are enough to get a remote config from an opamp server, parse it, apply it and ack it.
44+
45+
Since OpAMP APIs, config options or environment variables are not standardizes the distros are required
46+
to provide code doing so.
47+
OTel Python distros would need to provide their own message handler callback that implements the actual
48+
change of whatever configuration their backends sends.
49+
50+
Please note that the API is not finalized yet and so the name is called ``_opamp`` with the underscore.
51+
52+
Usage
53+
-----
54+
55+
.. code-block:: python
56+
57+
import os
58+
59+
from opentelemetry._opamp import messages
60+
from opentelemetry._opamp.agent import OpAMPAgent
61+
from opentelemetry._opamp.client import OpAMPClient
62+
from opentelemetry._opamp.proto import opamp_pb2 as opamp_pb2
63+
from opentelemetry.sdk._configuration import _OTelSDKConfigurator
64+
from opentelemetry.sdk.resources import OTELResourceDetector
65+
66+
67+
def opamp_handler(agent: OpAMPAgent, client: OpAMPClient, message: opamp_pb2.ServerToAgent):
68+
for config_filename, config in messages._decode_remote_config(message.remote_config):
69+
print("do something")
70+
71+
72+
class MyOpenTelemetryConfigurator(_OTelSDKConfigurator):
73+
def _configure(self, **kwargs):
74+
super()._configure(**kwargs)
75+
76+
enable_opamp = False
77+
endpoint = os.environ.get("OTEL_PYTHON_OPAMP_ENDPOINT")
78+
if endpoint:
79+
# this is not great but we don't have the calculated resource attributes around
80+
# see https://github.com/open-telemetry/opentelemetry-python/pull/4646 for creating
81+
# an entry point distros can implement
82+
resource = OTELResourceDetector().detect()
83+
agent_identifying_attributes = {
84+
"service.name": resource.attributes.get("service.name"),
85+
}
86+
opamp_client = OpAMPClient(
87+
endpoint=endpoint,
88+
agent_identifying_attributes=agent_identifying_attributes,
89+
)
90+
opamp_agent = OpAMPAgent(
91+
interval=30,
92+
message_handler=opamp_handler,
93+
client=opamp_client,
94+
)
95+
opamp_agent.start()
96+
97+
API
98+
---
99+
"""
100+
101+
30102
class _Job:
31103
"""
32104
Represents a single request job, with retry/backoff metadata.

opamp/opentelemetry-opamp-client/src/opentelemetry/_opamp/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343

4444

4545
class OpAMPClient:
46+
"""
47+
OpAMPClient implement the helpers for building and sending messages that the agent will use.
48+
"""
49+
4650
def __init__(
4751
self,
4852
*,

0 commit comments

Comments
 (0)