Files
opentelemetry-python-contrib/scripts/opamp_proto_codegen.sh
Riccardo Magliocchetti 88e5bfc630 Add a basic http OpAMP client (#3635)
* Add a basic http OpAMP client

* Add some docs and hook it into the system

Still not building content

* Add default value of 30 seconds to heartbeat message interval

* Fix docs build

* More docs improvements

* Fix spellcheck

* Remove local workaround

* Generate workflows and add to release script

* Fix typos in opamp lint commands

* Fix requirements for pylint

* Update opamp/opentelemetry-opamp-client/pyproject.toml

* Recreate requirements

* Add missing opentelemetry-api dependency

* Fix tox test commands

Drop opentelemetry api fixed version from requirements

* Fix tox

* Add baseline of vcrpy 7.0.0

* Ignore pb2 module in pylintrc

* Bump pylint to match the version in core

* Silence pylint warnings

* Don't trace opamp client own http requests

* Permit to pass a custom transport to client

And a custom session to RequestsTransport

* Don't bump pylint after all

* Fix pylint

* Try to typecheck opamp client

* Bump version after rebase

* Fix typecheck in client

* Please pyright in strict mode

* No need for functions and methods to be private since _opamp module is already private

* Add missing protobuf package installation for typecheck

* Fix docs generation

* Fix pyright exclusion rule for proto

Missed .pyi exclusion

* Feedback

* Don't flush the queue at exit

* Log transport send exceptions

* Update example to not assume that the config is in json format

* Fix typo in exception

* Looks like it's implementers

* Add timeout to stop to forward to threads join

* Clarify doc

* Fix typo in var name

* Add support for mTLS

* Add helpers for handling of ReportFullState ServerToAgent flag

Introducing basic handling of the ReportsEffectiveConfig capability

* Remove backup file

* Rewrite opamp_proto_codegen.sh to use uv

* Make the package releasable independently

* Send full state at connection

* Add 3.14 test run

* Add changelog entry

* Add missing ReportsEffectiveConfig capability in documentation

* Start version from 0.1b0 and re-record e2e tests

* Record tests against opentelemetry-go

---------

Co-authored-by: Emídio Neto <9735060+emdneto@users.noreply.github.com>
2026-03-05 16:36:54 +01:00

75 lines
2.4 KiB
Bash
Executable File

#!/bin/bash
# Copyright The OpenTelemetry Authors
#
# 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
#
# 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.
# Regenerate python code from opamp protos in
# https://github.com/open-telemetry/opamp-spec
#
# To use, update OPAMP_SPEC_REPO_BRANCH_OR_COMMIT variable below to a commit hash or
# tag in opentelemtry-proto repo that you want to build off of. Then, just run
# this script to update the proto files. Commit the changes as well as any
# fixes needed in the OTLP exporter.
#
# Optional envars:
# OPAMP_SPEC_REPO_DIR - the path to an existing checkout of the opamp-spec repo
# Pinned commit/branch/tag for the current version used in the opamp python package.
OPAMP_SPEC_REPO_BRANCH_OR_COMMIT="v0.12.0"
set -e
OPAMP_SPEC_REPO_DIR=${OPAMP_SPEC_REPO_DIR:-"/tmp/opamp-spec"}
# root of opentelemetry-python repo
repo_root="$(git rev-parse --show-toplevel)"
proto_output_dir="$repo_root/opamp/opentelemetry-opamp-client/src/opentelemetry/_opamp/proto"
protoc() {
uvx -c $repo_root/opamp-gen-requirements.txt \
--python 3.12 \
--from grpcio-tools \
--with mypy-protobuf \
python -m grpc_tools.protoc "$@"
}
protoc --version
# Clone the proto repo if it doesn't exist
if [ ! -d "$OPAMP_SPEC_REPO_DIR" ]; then
git clone https://github.com/open-telemetry/opamp-spec.git $OPAMP_SPEC_REPO_DIR
fi
# Pull in changes and switch to requested branch
(
cd $OPAMP_SPEC_REPO_DIR
git fetch --all
git checkout $OPAMP_SPEC_REPO_BRANCH_OR_COMMIT
# pull if OPAMP_SPEC_BRANCH_OR_COMMIT is not a detached head
git symbolic-ref -q HEAD && git pull --ff-only || true
)
cd $proto_output_dir
# clean up old generated code
find . -regex ".*_pb2.*\.pyi?" -exec rm {} +
# generate proto code for all protos
all_protos=$(find $OPAMP_SPEC_REPO_DIR/ -name "*.proto")
protoc \
-I $OPAMP_SPEC_REPO_DIR/proto \
--python_out=. \
--mypy_out=. \
$all_protos
sed -i -e 's/import anyvalue_pb2 as anyvalue__pb2/from . import anyvalue_pb2 as anyvalue__pb2/' opamp_pb2.py