From c0d60056a667891151f38acef4a46dafd488625c Mon Sep 17 00:00:00 2001 From: Jeevan Singh Opel Date: Fri, 22 Nov 2024 00:25:39 +0000 Subject: [PATCH] Add vendor script --- scripts/vendor_otlp_proto_common.sh | 54 +++++++++++++++++++ .../exporter/otlp/proto/common/__init__.py | 2 +- .../otlp/proto/common/_internal/__init__.py | 6 ++- .../common/_internal/_log_encoder/__init__.py | 2 +- .../_internal/metrics_encoder/__init__.py | 4 +- .../_internal/trace_encoder/__init__.py | 2 +- .../otlp/proto/common/_log_encoder.py | 2 +- .../otlp/proto/common/metrics_encoder.py | 2 +- .../exporter/otlp/proto/common/py.typed | 0 .../otlp/proto/common/trace_encoder.py | 2 +- .../exporter/otlp/proto/common/version.py | 2 +- 11 files changed, 68 insertions(+), 10 deletions(-) create mode 100755 scripts/vendor_otlp_proto_common.sh create mode 100644 src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/py.typed diff --git a/scripts/vendor_otlp_proto_common.sh b/scripts/vendor_otlp_proto_common.sh new file mode 100755 index 0000000..24adf7c --- /dev/null +++ b/scripts/vendor_otlp_proto_common.sh @@ -0,0 +1,54 @@ +#!/bin/bash +# +# Vendor in the python code in +# https://github.com/open-telemetry/opentelemetry-python/tree/main/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common +# +# To use, update REPO_BRANCH_OR_COMMIT variable below to a commit hash or +# tag in opentelemtry-python 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. + +# Pinned commit/branch/tag for the current version used in opentelemetry-proto python package. +REPO_BRANCH_OR_COMMIT="v1.26.0" + +set -e + +REPO_DIR=${REPO_DIR:-"/tmp/opentelemetry-python"} +# root of opentelemetry-python repo +repo_root="$(git rev-parse --show-toplevel)" + +# Clone the proto repo if it doesn't exist +if [ ! -d "$REPO_DIR" ]; then + git clone https://github.com/open-telemetry/opentelemetry-python.git $REPO_DIR +fi + +# Pull in changes and switch to requested branch +( + cd $REPO_DIR + git fetch --all + git checkout $REPO_BRANCH_OR_COMMIT + # pull if REPO_BRANCH_OR_COMMIT is not a detached head + git symbolic-ref -q HEAD && git pull --ff-only || true +) + +cd $repo_root/src/snowflake/telemetry/_internal + +# Copy the entire file tree from exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/ +# to src/snowflake/telemetry/_internal/opentelemetry/ +cp -r $REPO_DIR/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter opentelemetry/ + +# If MacOS need '' after -i +# Detect the OS (macOS or Linux) +if [[ "$OSTYPE" == "darwin"* ]]; then + SED_CMD="sed -i ''" +else + SED_CMD="sed -i" +fi + +# Replace all the imports strings in the copied python files +# opentelemetry.exporter to snowflake.telemetry._internal.opentelemetry.exporter +# opentelemetry.proto.*_pb2 to snowflake.telemetry._internal.opentelemetry.proto.*_marshaler + +find opentelemetry/exporter -type f -name "*.py" -exec $SED_CMD 's/opentelemetry.exporter/snowflake.telemetry._internal.opentelemetry.exporter/g' {} + +find opentelemetry/exporter -type f -name "*.py" -exec $SED_CMD -i 's/opentelemetry\.proto\(.*\)_pb2/snowflake.telemetry._internal.opentelemetry.proto\1_marshaler/g' {} + + diff --git a/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/__init__.py b/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/__init__.py index 0672980..dffaa32 100644 --- a/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/__init__.py +++ b/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/__init__.py @@ -15,4 +15,4 @@ from snowflake.telemetry._internal.opentelemetry.exporter.otlp.proto.common.version import __version__ -__all__ = ["__version__"] \ No newline at end of file +__all__ = ["__version__"] diff --git a/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/_internal/__init__.py b/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/_internal/__init__.py index b07bad4..fe1c776 100644 --- a/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/_internal/__init__.py +++ b/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/_internal/__init__.py @@ -147,12 +147,15 @@ def _create_exp_backoff_generator(max_value: int = 0) -> Iterator[int]: from 1 (2^0) and doubles each time (2^1, 2^2, 2^3, ...). If a max_value is specified and non-zero, the generated values will not exceed this maximum, capping at max_value instead of growing indefinitely. + Parameters: - max_value (int, optional): The maximum value to yield. If 0 or not provided, the sequence grows without bound. + Returns: Iterator[int]: An iterator that yields the exponential backoff values, either uncapped or capped at max_value. + Example: ``` gen = _create_exp_backoff_generator(max_value=10) @@ -165,8 +168,9 @@ def _create_exp_backoff_generator(max_value: int = 0) -> Iterator[int]: 4 8 10 + Note: this functionality used to be handled by the 'backoff' package. """ for i in count(0): out = 2**i - yield min(out, max_value) if max_value else out \ No newline at end of file + yield min(out, max_value) if max_value else out diff --git a/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/_internal/_log_encoder/__init__.py b/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/_internal/_log_encoder/__init__.py index ca38cf4..916d5d6 100644 --- a/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/_internal/_log_encoder/__init__.py +++ b/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/_internal/_log_encoder/__init__.py @@ -92,4 +92,4 @@ def _encode_resource_logs(batch: Sequence[LogData]) -> List[ResourceLogs]: ) ) - return pb2_resource_logs \ No newline at end of file + return pb2_resource_logs diff --git a/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py b/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py index 481aacd..5620f17 100644 --- a/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py +++ b/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py @@ -39,7 +39,7 @@ ExportMetricsServiceRequest, ) from snowflake.telemetry._internal.opentelemetry.proto.common.v1.common_marshaler import InstrumentationScope -import snowflake.telemetry._internal.opentelemetry.proto.metrics.v1.metrics_marshaler as pb2 +from snowflake.telemetry._internal.opentelemetry.proto.metrics.v1 import metrics_marshaler as pb2 from opentelemetry.sdk.metrics.export import ( MetricsData, Gauge, @@ -335,4 +335,4 @@ def encode_metrics(data: MetricsData) -> ExportMetricsServiceRequest: ) ) resource_metrics = resource_data - return ExportMetricsServiceRequest(resource_metrics=resource_metrics) \ No newline at end of file + return ExportMetricsServiceRequest(resource_metrics=resource_metrics) diff --git a/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/_internal/trace_encoder/__init__.py b/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/_internal/trace_encoder/__init__.py index 84f00fb..8243860 100644 --- a/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/_internal/trace_encoder/__init__.py +++ b/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/_internal/trace_encoder/__init__.py @@ -186,4 +186,4 @@ def _encode_trace_state(trace_state: TraceState) -> Optional[str]: def _encode_parent_id(context: Optional[SpanContext]) -> Optional[bytes]: if context: return _encode_span_id(context.span_id) - return None \ No newline at end of file + return None diff --git a/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/_log_encoder.py b/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/_log_encoder.py index e436c83..4e761cd 100644 --- a/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/_log_encoder.py +++ b/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/_log_encoder.py @@ -17,4 +17,4 @@ encode_logs, ) -__all__ = ["encode_logs"] \ No newline at end of file +__all__ = ["encode_logs"] diff --git a/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/metrics_encoder.py b/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/metrics_encoder.py index 410dbbf..a8425de 100644 --- a/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/metrics_encoder.py +++ b/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/metrics_encoder.py @@ -17,4 +17,4 @@ encode_metrics, ) -__all__ = ["encode_metrics"] \ No newline at end of file +__all__ = ["encode_metrics"] diff --git a/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/py.typed b/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/py.typed new file mode 100644 index 0000000..e69de29 diff --git a/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/trace_encoder.py b/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/trace_encoder.py index f4355f5..d5896eb 100644 --- a/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/trace_encoder.py +++ b/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/trace_encoder.py @@ -17,4 +17,4 @@ encode_spans, ) -__all__ = ["encode_spans"] \ No newline at end of file +__all__ = ["encode_spans"] diff --git a/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/version.py b/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/version.py index 43c3dbd..02b6cd0 100644 --- a/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/version.py +++ b/src/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "1.26.0" \ No newline at end of file +__version__ = "1.26.0"