Skip to content

Commit

Permalink
Internalize opentelemetry-exporter-otlp-proto-common adapter code (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jopel authored Dec 11, 2024
1 parent 1f5f4a8 commit 196413d
Show file tree
Hide file tree
Showing 25 changed files with 1,503 additions and 29 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/check-vendor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This workflow will delete and regenerate the opentelemetry-exporter-otlp-proto-common code using scripts/vendor_otlp_proto_common.sh.
# If generating the code produces any changes from what is currently checked in, the workflow will fail and prompt the user to regenerate the code.
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Check OTLP Proto Common Vendored Code

on:
push:
branches: [ "main" ]
paths:
- "scripts/vendor_otlp_proto_common.sh"
- "src/snowflake/telemetry/_internal/opentelemetry/exporter/**"
- ".github/workflows/check-vendor.yml"
pull_request:
branches: [ "main" ]
paths:
- "scripts/vendor_otlp_proto_common.sh"
- "src/snowflake/telemetry/_internal/opentelemetry/exporter/**"
- ".github/workflows/check-vendor.yml"

jobs:
check-codegen:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run vendor script
run: |
rm -rf src/snowflake/telemetry/_internal/opentelemetry/exporter/
./scripts/vendor_otlp_proto_common.sh
- name: Check for changes
run: |
git diff --exit-code || { echo "Code generation produced changes! Regenerate the code using ./scripts/vendor_otlp_proto_common.sh"; exit 1; }
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

* Upgrade OpenTelemetry Python dependencies to version 1.26.0
* Vendored in adapter code from package opentelemetry-exporter-otlp-proto-common and replaced protobuf dependency with custom vanilla python serialization

## 0.5.0 (2024-07-23)

Expand Down
1 change: 0 additions & 1 deletion anaconda/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ requirements:
run:
- python
- opentelemetry-api ==1.26.0
- opentelemetry-exporter-otlp-proto-common ==1.26.0
- opentelemetry-sdk ==1.26.0

about:
Expand Down
86 changes: 86 additions & 0 deletions benchmark/benchmark_serialize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import google_benchmark as benchmark

from util import get_logs_data, get_metrics_data, get_traces_data, get_logs_data_4MB

from snowflake.telemetry._internal.opentelemetry.exporter.otlp.proto.common._log_encoder import encode_logs
from snowflake.telemetry._internal.opentelemetry.exporter.otlp.proto.common.metrics_encoder import encode_metrics
from snowflake.telemetry._internal.opentelemetry.exporter.otlp.proto.common.trace_encoder import encode_spans

from opentelemetry.exporter.otlp.proto.common._log_encoder import encode_logs as pb2_encode_logs
from opentelemetry.exporter.otlp.proto.common.metrics_encoder import encode_metrics as pb2_encode_metrics
from opentelemetry.exporter.otlp.proto.common.trace_encoder import encode_spans as pb2_encode_spans

"""
------------------------------------------------------------------------------
Benchmark Time CPU Iterations
------------------------------------------------------------------------------
test_bm_serialize_logs_data_4MB 730591536 ns 730562298 ns 1
test_bm_pb2_serialize_logs_data_4MB 702522039 ns 702490893 ns 1
test_bm_serialize_logs_data 100882 ns 100878 ns 6930
test_bm_pb2_serialize_logs_data 97112 ns 97109 ns 7195
test_bm_serialize_metrics_data 114938 ns 114934 ns 6096
test_bm_pb2_serialize_metrics_data 161849 ns 161845 ns 4324
test_bm_serialize_traces_data 123977 ns 123973 ns 5633
test_bm_pb2_serialize_traces_data 131016 ns 131011 ns 5314
"""

def sanity_check():
logs_data = get_logs_data()
metrics_data = get_metrics_data()
traces_data = get_traces_data()

assert encode_logs(logs_data).SerializeToString() == pb2_encode_logs(logs_data).SerializeToString()
assert encode_metrics(metrics_data).SerializeToString() == pb2_encode_metrics(metrics_data).SerializeToString()
assert encode_spans(traces_data).SerializeToString() == pb2_encode_spans(traces_data).SerializeToString()

@benchmark.register
def test_bm_serialize_logs_data_4MB(state):
logs_data = get_logs_data_4MB()
while state:
encode_logs(logs_data).SerializeToString()

@benchmark.register
def test_bm_pb2_serialize_logs_data_4MB(state):
logs_data = get_logs_data_4MB()
while state:
pb2_encode_logs(logs_data).SerializeToString()

@benchmark.register
def test_bm_serialize_logs_data(state):
logs_data = get_logs_data()
while state:
encode_logs(logs_data).SerializeToString()

@benchmark.register
def test_bm_pb2_serialize_logs_data(state):
logs_data = get_logs_data()
while state:
pb2_encode_logs(logs_data).SerializeToString()

@benchmark.register
def test_bm_serialize_metrics_data(state):
metrics_data = get_metrics_data()
while state:
encode_metrics(metrics_data).SerializeToString()

@benchmark.register
def test_bm_pb2_serialize_metrics_data(state):
metrics_data = get_metrics_data()
while state:
pb2_encode_metrics(metrics_data).SerializeToString()

@benchmark.register
def test_bm_serialize_traces_data(state):
traces_data = get_traces_data()
while state:
encode_spans(traces_data).SerializeToString()

@benchmark.register
def test_bm_pb2_serialize_traces_data(state):
traces_data = get_traces_data()
while state:
pb2_encode_spans(traces_data).SerializeToString()

if __name__ == "__main__":
sanity_check()
benchmark.main()
Loading

0 comments on commit 196413d

Please sign in to comment.