From 7abe6de716d36ca2e6a515db72099e14d9fe77e6 Mon Sep 17 00:00:00 2001 From: Tim Pansino Date: Tue, 15 Oct 2024 14:41:49 -0700 Subject: [PATCH 1/3] Add infinite tracing protobuf v5 files --- newrelic/core/infinite_tracing.proto | 41 ++++++++++++++ newrelic/core/infinite_tracing_pb2.py | 13 ++++- newrelic/core/infinite_tracing_v3_pb2.py | 2 +- newrelic/core/infinite_tracing_v4_pb2.py | 2 +- newrelic/core/infinite_tracing_v5_pb2.py | 70 ++++++++++++++++++++++++ tox.ini | 5 +- 6 files changed, 126 insertions(+), 7 deletions(-) create mode 100644 newrelic/core/infinite_tracing.proto create mode 100644 newrelic/core/infinite_tracing_v5_pb2.py diff --git a/newrelic/core/infinite_tracing.proto b/newrelic/core/infinite_tracing.proto new file mode 100644 index 0000000000..513dd6904e --- /dev/null +++ b/newrelic/core/infinite_tracing.proto @@ -0,0 +1,41 @@ +// Generate pb2 files using the following command: +// python -m grpc_tools.protoc --proto_path=newrelic/core --python_out=newrelic/core newrelic/core/infinite_tracing.proto + +syntax = "proto3"; + +package com.newrelic.trace.v1; + +service IngestService { + // Accepts a stream of Span messages, and returns an irregular stream of + // RecordStatus messages. + rpc RecordSpan(stream Span) returns (stream RecordStatus) {} + + // Accepts a stream of SpanBatch messages, and returns an irregular + // stream of RecordStatus messages. This endpoint can be used to improve + // throughput when Span messages are small + rpc RecordSpanBatch(stream SpanBatch) returns (stream RecordStatus) {} +} + +message SpanBatch { + repeated Span spans = 1; +} + +message Span { + string trace_id = 1; + map intrinsics = 2; + map user_attributes = 3; + map agent_attributes = 4; +} + +message AttributeValue { + oneof value { + string string_value = 1; + bool bool_value = 2; + int64 int_value = 3; + double double_value = 4; + } +} + +message RecordStatus { + uint64 messages_seen = 1; +} \ No newline at end of file diff --git a/newrelic/core/infinite_tracing_pb2.py b/newrelic/core/infinite_tracing_pb2.py index 278dc6d186..9c888d21c1 100644 --- a/newrelic/core/infinite_tracing_pb2.py +++ b/newrelic/core/infinite_tracing_pb2.py @@ -13,14 +13,21 @@ # limitations under the License. try: - from google.protobuf import __version__ + from google.protobuf import __version__ as _protobuf_version - PROTOBUF_VERSION = tuple(int(v) for v in __version__.split(".")) + PROTOBUF_VERSION = tuple(int(v) for v in _protobuf_version.split(".")) except Exception: PROTOBUF_VERSION = (0, 0, 0) # Import appropriate generated pb2 file for protobuf version -if PROTOBUF_VERSION >= (4,): +if PROTOBUF_VERSION >= (5,): + from newrelic.core.infinite_tracing_v5_pb2 import ( # noqa: F401; pylint: disable=W0611 + AttributeValue, + RecordStatus, + Span, + SpanBatch, + ) +elif PROTOBUF_VERSION >= (4,): from newrelic.core.infinite_tracing_v4_pb2 import ( # noqa: F401; pylint: disable=W0611 AttributeValue, RecordStatus, diff --git a/newrelic/core/infinite_tracing_v3_pb2.py b/newrelic/core/infinite_tracing_v3_pb2.py index 79e3ec4eb1..af172e9d05 100644 --- a/newrelic/core/infinite_tracing_v3_pb2.py +++ b/newrelic/core/infinite_tracing_v3_pb2.py @@ -13,7 +13,7 @@ # limitations under the License. # Generated by the protocol buffer compiler. DO NOT EDIT! -# source: v1.proto +# source: infinite_tracing.proto """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool diff --git a/newrelic/core/infinite_tracing_v4_pb2.py b/newrelic/core/infinite_tracing_v4_pb2.py index 79e3ec4eb1..af172e9d05 100644 --- a/newrelic/core/infinite_tracing_v4_pb2.py +++ b/newrelic/core/infinite_tracing_v4_pb2.py @@ -13,7 +13,7 @@ # limitations under the License. # Generated by the protocol buffer compiler. DO NOT EDIT! -# source: v1.proto +# source: infinite_tracing.proto """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool diff --git a/newrelic/core/infinite_tracing_v5_pb2.py b/newrelic/core/infinite_tracing_v5_pb2.py new file mode 100644 index 0000000000..1b352aabce --- /dev/null +++ b/newrelic/core/infinite_tracing_v5_pb2.py @@ -0,0 +1,70 @@ +# -*- coding: utf-8 -*- +# # Copyright 2010 New Relic, Inc. +# +# 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. + +# Generated by the protocol buffer compiler. DO NOT EDIT! +# NO CHECKED-IN PROTOBUF GENCODE +# source: infinite_tracing.proto +# Protobuf Python Version: 5.27.2 +"""Generated protocol buffer code.""" +from google.protobuf import descriptor as _descriptor +from google.protobuf import descriptor_pool as _descriptor_pool +from google.protobuf import runtime_version as _runtime_version +from google.protobuf import symbol_database as _symbol_database +from google.protobuf.internal import builder as _builder +_runtime_version.ValidateProtobufRuntimeVersion( + _runtime_version.Domain.PUBLIC, + 5, + 27, + 2, + '', + 'infinite_tracing.proto' +) +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x16infinite_tracing.proto\x12\x15\x63om.newrelic.trace.v1\"7\n\tSpanBatch\x12*\n\x05spans\x18\x01 \x03(\x0b\x32\x1b.com.newrelic.trace.v1.Span\"\x86\x04\n\x04Span\x12\x10\n\x08trace_id\x18\x01 \x01(\t\x12?\n\nintrinsics\x18\x02 \x03(\x0b\x32+.com.newrelic.trace.v1.Span.IntrinsicsEntry\x12H\n\x0fuser_attributes\x18\x03 \x03(\x0b\x32/.com.newrelic.trace.v1.Span.UserAttributesEntry\x12J\n\x10\x61gent_attributes\x18\x04 \x03(\x0b\x32\x30.com.newrelic.trace.v1.Span.AgentAttributesEntry\x1aX\n\x0fIntrinsicsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\x34\n\x05value\x18\x02 \x01(\x0b\x32%.com.newrelic.trace.v1.AttributeValue:\x02\x38\x01\x1a\\\n\x13UserAttributesEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\x34\n\x05value\x18\x02 \x01(\x0b\x32%.com.newrelic.trace.v1.AttributeValue:\x02\x38\x01\x1a]\n\x14\x41gentAttributesEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\x34\n\x05value\x18\x02 \x01(\x0b\x32%.com.newrelic.trace.v1.AttributeValue:\x02\x38\x01\"t\n\x0e\x41ttributeValue\x12\x16\n\x0cstring_value\x18\x01 \x01(\tH\x00\x12\x14\n\nbool_value\x18\x02 \x01(\x08H\x00\x12\x13\n\tint_value\x18\x03 \x01(\x03H\x00\x12\x16\n\x0c\x64ouble_value\x18\x04 \x01(\x01H\x00\x42\x07\n\x05value\"%\n\x0cRecordStatus\x12\x15\n\rmessages_seen\x18\x01 \x01(\x04\x32\xc5\x01\n\rIngestService\x12T\n\nRecordSpan\x12\x1b.com.newrelic.trace.v1.Span\x1a#.com.newrelic.trace.v1.RecordStatus\"\x00(\x01\x30\x01\x12^\n\x0fRecordSpanBatch\x12 .com.newrelic.trace.v1.SpanBatch\x1a#.com.newrelic.trace.v1.RecordStatus\"\x00(\x01\x30\x01\x62\x06proto3') + +_globals = globals() +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'infinite_tracing_pb2', _globals) +if not _descriptor._USE_C_DESCRIPTORS: + DESCRIPTOR._loaded_options = None + _globals['_SPAN_INTRINSICSENTRY']._loaded_options = None + _globals['_SPAN_INTRINSICSENTRY']._serialized_options = b'8\001' + _globals['_SPAN_USERATTRIBUTESENTRY']._loaded_options = None + _globals['_SPAN_USERATTRIBUTESENTRY']._serialized_options = b'8\001' + _globals['_SPAN_AGENTATTRIBUTESENTRY']._loaded_options = None + _globals['_SPAN_AGENTATTRIBUTESENTRY']._serialized_options = b'8\001' + _globals['_SPANBATCH']._serialized_start=49 + _globals['_SPANBATCH']._serialized_end=104 + _globals['_SPAN']._serialized_start=107 + _globals['_SPAN']._serialized_end=625 + _globals['_SPAN_INTRINSICSENTRY']._serialized_start=348 + _globals['_SPAN_INTRINSICSENTRY']._serialized_end=436 + _globals['_SPAN_USERATTRIBUTESENTRY']._serialized_start=438 + _globals['_SPAN_USERATTRIBUTESENTRY']._serialized_end=530 + _globals['_SPAN_AGENTATTRIBUTESENTRY']._serialized_start=532 + _globals['_SPAN_AGENTATTRIBUTESENTRY']._serialized_end=625 + _globals['_ATTRIBUTEVALUE']._serialized_start=627 + _globals['_ATTRIBUTEVALUE']._serialized_end=743 + _globals['_RECORDSTATUS']._serialized_start=745 + _globals['_RECORDSTATUS']._serialized_end=782 + _globals['_INGESTSERVICE']._serialized_start=785 + _globals['_INGESTSERVICE']._serialized_end=982 +# @@protoc_insertion_point(module_scope) diff --git a/tox.ini b/tox.ini index 09b2aa3c96..16e56b20a7 100644 --- a/tox.ini +++ b/tox.ini @@ -94,8 +94,8 @@ envlist = python-adapter_waitress-{py37,py38,py39}-waitress010404, python-agent_features-{py37,py38,py39,py310,py311,py312,py313}-{with,without}_extensions, python-agent_features-pypy310-without_extensions, - python-agent_streaming-{py37,py38,py39,py310,py311,py312,py313}-protobuf04-{with,without}_extensions, - python-agent_streaming-py39-protobuf{03,0319}-{with,without}_extensions, + python-agent_streaming-{py37,py38,py39,py310,py311,py312,py313}-protobuf05-{with,without}_extensions, + python-agent_streaming-py39-protobuf{03,0319,04}-{with,without}_extensions, python-agent_unittests-{py37,py38,py39,py310,py311,py312,py313}-{with,without}_extensions, python-agent_unittests-pypy310-without_extensions, python-application_celery-{py37,py38,py39,py310,py311,py312,py313,pypy310}-celerylatest, @@ -217,6 +217,7 @@ deps = adapter_waitress-waitresslatest: waitress agent_features: beautifulsoup4 agent_features: protobuf + agent_streaming-protobuf05: protobuf<6 agent_streaming-protobuf04: protobuf<5 agent_streaming-protobuf03: protobuf<4 agent_streaming-protobuf0319: protobuf<3.20 From 5a6a33437a3761d5732cf3f4e9542a6d0cfb0ae9 Mon Sep 17 00:00:00 2001 From: Tim Pansino Date: Thu, 17 Oct 2024 12:01:14 -0700 Subject: [PATCH 2/3] Attempt to load protobuf files without version checks --- newrelic/core/infinite_tracing_pb2.py | 44 +++++++++++++-------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/newrelic/core/infinite_tracing_pb2.py b/newrelic/core/infinite_tracing_pb2.py index 9c888d21c1..3149d53d92 100644 --- a/newrelic/core/infinite_tracing_pb2.py +++ b/newrelic/core/infinite_tracing_pb2.py @@ -12,32 +12,32 @@ # See the License for the specific language governing permissions and # limitations under the License. +# Protobuf v5 Files try: - from google.protobuf import __version__ as _protobuf_version - - PROTOBUF_VERSION = tuple(int(v) for v in _protobuf_version.split(".")) -except Exception: - PROTOBUF_VERSION = (0, 0, 0) - -# Import appropriate generated pb2 file for protobuf version -if PROTOBUF_VERSION >= (5,): from newrelic.core.infinite_tracing_v5_pb2 import ( # noqa: F401; pylint: disable=W0611 AttributeValue, RecordStatus, Span, SpanBatch, ) -elif PROTOBUF_VERSION >= (4,): - from newrelic.core.infinite_tracing_v4_pb2 import ( # noqa: F401; pylint: disable=W0611 - AttributeValue, - RecordStatus, - Span, - SpanBatch, - ) -else: - from newrelic.core.infinite_tracing_v3_pb2 import ( # noqa: F401; pylint: disable=W0611 - AttributeValue, - RecordStatus, - Span, - SpanBatch, - ) +except Exception: + # Protobuf v4 Files + try: + from newrelic.core.infinite_tracing_v4_pb2 import ( # noqa: F401; pylint: disable=W0611 + AttributeValue, + RecordStatus, + Span, + SpanBatch, + ) + except Exception: + # Protobuf v3 Files + try: + from newrelic.core.infinite_tracing_v3_pb2 import ( # noqa: F401; pylint: disable=W0611 + AttributeValue, + RecordStatus, + Span, + SpanBatch, + ) + except Exception: + pass + From d21a5b85b6e19c7b329ea82a0bd467bc5ba8b272 Mon Sep 17 00:00:00 2001 From: Tim Pansino Date: Thu, 24 Oct 2024 14:25:35 -0700 Subject: [PATCH 3/3] Revert to using protobuf version for imports --- newrelic/core/infinite_tracing_pb2.py | 44 +++++++++++++-------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/newrelic/core/infinite_tracing_pb2.py b/newrelic/core/infinite_tracing_pb2.py index 3149d53d92..b645a62a1c 100644 --- a/newrelic/core/infinite_tracing_pb2.py +++ b/newrelic/core/infinite_tracing_pb2.py @@ -12,32 +12,32 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Protobuf v5 Files try: + from google.protobuf import __version__ + + PROTOBUF_VERSION = tuple(int(v) for v in __version__.split(".")) +except Exception: + PROTOBUF_VERSION = (0, 0, 0) + +# Import appropriate generated pb2 file for protobuf version +if PROTOBUF_VERSION >= (5,): from newrelic.core.infinite_tracing_v5_pb2 import ( # noqa: F401; pylint: disable=W0611 AttributeValue, RecordStatus, Span, SpanBatch, ) -except Exception: - # Protobuf v4 Files - try: - from newrelic.core.infinite_tracing_v4_pb2 import ( # noqa: F401; pylint: disable=W0611 - AttributeValue, - RecordStatus, - Span, - SpanBatch, - ) - except Exception: - # Protobuf v3 Files - try: - from newrelic.core.infinite_tracing_v3_pb2 import ( # noqa: F401; pylint: disable=W0611 - AttributeValue, - RecordStatus, - Span, - SpanBatch, - ) - except Exception: - pass - +elif PROTOBUF_VERSION >= (4,): + from newrelic.core.infinite_tracing_v4_pb2 import ( # noqa: F401; pylint: disable=W0611 + AttributeValue, + RecordStatus, + Span, + SpanBatch, + ) +else: + from newrelic.core.infinite_tracing_v3_pb2 import ( # noqa: F401; pylint: disable=W0611 + AttributeValue, + RecordStatus, + Span, + SpanBatch, + )