Skip to content

Commit 1224637

Browse files
Bump to use otel proto v1.7.0 and update proto files
1 parent 1871d26 commit 1224637

File tree

8 files changed

+1377
-2
lines changed

8 files changed

+1377
-2
lines changed

scripts/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def from_descriptor(descriptor: FieldDescriptorProto, group: Optional[str] = Non
183183

184184
if proto_type == "message" or proto_type == "enum":
185185
# Extract the class name of message fields, to use as python type
186-
python_type = re.sub(r"^[a-zA-Z0-9_\.]+\.v1\.", "", descriptor.type_name)
186+
python_type = re.sub(r"^[a-zA-Z0-9_\.]+\.v1[a-zA-Z0-9]*\.", "", descriptor.type_name)
187187

188188
repeated = descriptor.label == FieldDescriptorProto.LABEL_REPEATED
189189
if repeated:

scripts/proto_codegen.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# PROTO_REPO_DIR - the path to an existing checkout of the opentelemetry-proto repo
1313

1414
# Pinned commit/branch/tag for the current version used in opentelemetry-proto python package.
15-
PROTO_REPO_BRANCH_OR_COMMIT="v1.2.0"
15+
PROTO_REPO_BRANCH_OR_COMMIT="v1.7.0"
1616

1717
set -e
1818

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
# Generated by the protoc compiler with a custom plugin. DO NOT EDIT!
2+
# sources: opentelemetry/proto/collector/profiles/v1development/profiles_service.proto
3+
#
4+
# Copyright (c) 2012-2024 Snowflake Inc. All rights reserved.
5+
#
6+
# Copyright 2023, OpenTelemetry Authors
7+
#
8+
# Licensed under the Apache License, Version 2.0 (the "License");
9+
# you may not use this file except in compliance with the License.
10+
# You may obtain a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS,
16+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
# See the License for the specific language governing permissions and
18+
# limitations under the License.
19+
#
20+
# This file has been generated from the original proto schema at
21+
#
22+
# https://github.com/open-telemetry/opentelemetry-proto
23+
#
24+
# using a custom protoc compiler plugin by Snowflake Inc.
25+
26+
from __future__ import annotations
27+
28+
import struct
29+
from typing import List
30+
31+
from snowflake.telemetry._internal.opentelemetry.proto.profiles.v1development.profiles_marshaler import *
32+
from snowflake.telemetry._internal.serialize import (
33+
Enum,
34+
MessageMarshaler,
35+
Varint,
36+
)
37+
38+
39+
class ExportProfilesServiceRequest(MessageMarshaler):
40+
@property
41+
def resource_profiles(self) -> List[ResourceProfiles]:
42+
if self._resource_profiles is None:
43+
self._resource_profiles = list()
44+
return self._resource_profiles
45+
46+
@property
47+
def dictionary(self) -> ProfilesDictionary:
48+
if self._dictionary is None:
49+
self._dictionary = ProfilesDictionary()
50+
return self._dictionary
51+
52+
def __init__(
53+
self,
54+
resource_profiles: List[ResourceProfiles] = None,
55+
dictionary: ProfilesDictionary = None,
56+
):
57+
self._resource_profiles: List[ResourceProfiles] = resource_profiles
58+
self._dictionary: ProfilesDictionary = dictionary
59+
60+
def calculate_size(self) -> int:
61+
size = 0
62+
if self._resource_profiles:
63+
size += sum(
64+
message._get_size()
65+
+ len(b"\n")
66+
+ Varint.size_varint_u32(message._get_size())
67+
for message in self._resource_profiles
68+
)
69+
if self._dictionary is not None:
70+
size += (
71+
len(b"\x12")
72+
+ Varint.size_varint_u32(self._dictionary._get_size())
73+
+ self._dictionary._get_size()
74+
)
75+
return size
76+
77+
def write_to(self, out: bytearray) -> None:
78+
if self._resource_profiles:
79+
for v in self._resource_profiles:
80+
out += b"\n"
81+
Varint.write_varint_u32(out, v._get_size())
82+
v.write_to(out)
83+
if self._dictionary is not None:
84+
out += b"\x12"
85+
Varint.write_varint_u32(out, self._dictionary._get_size())
86+
self._dictionary.write_to(out)
87+
88+
89+
class ExportProfilesServiceResponse(MessageMarshaler):
90+
@property
91+
def partial_success(self) -> ExportProfilesPartialSuccess:
92+
if self._partial_success is None:
93+
self._partial_success = ExportProfilesPartialSuccess()
94+
return self._partial_success
95+
96+
def __init__(
97+
self,
98+
partial_success: ExportProfilesPartialSuccess = None,
99+
):
100+
self._partial_success: ExportProfilesPartialSuccess = partial_success
101+
102+
def calculate_size(self) -> int:
103+
size = 0
104+
if self._partial_success is not None:
105+
size += (
106+
len(b"\n")
107+
+ Varint.size_varint_u32(self._partial_success._get_size())
108+
+ self._partial_success._get_size()
109+
)
110+
return size
111+
112+
def write_to(self, out: bytearray) -> None:
113+
if self._partial_success is not None:
114+
out += b"\n"
115+
Varint.write_varint_u32(out, self._partial_success._get_size())
116+
self._partial_success.write_to(out)
117+
118+
119+
class ExportProfilesPartialSuccess(MessageMarshaler):
120+
rejected_profiles: int
121+
error_message: str
122+
123+
def __init__(
124+
self,
125+
rejected_profiles: int = 0,
126+
error_message: str = "",
127+
):
128+
self.rejected_profiles: int = rejected_profiles
129+
self.error_message: str = error_message
130+
131+
def calculate_size(self) -> int:
132+
size = 0
133+
if self.rejected_profiles:
134+
size += len(b"\x08") + Varint.size_varint_i64(self.rejected_profiles)
135+
if self.error_message:
136+
v = self.error_message.encode("utf-8")
137+
size += len(b"\x12") + Varint.size_varint_u32(len(v)) + len(v)
138+
return size
139+
140+
def write_to(self, out: bytearray) -> None:
141+
if self.rejected_profiles:
142+
out += b"\x08"
143+
Varint.write_varint_i64(out, self.rejected_profiles)
144+
if self.error_message:
145+
v = self.error_message.encode("utf-8")
146+
out += b"\x12"
147+
Varint.write_varint_u32(out, len(v))
148+
out += v

src/snowflake/telemetry/_internal/opentelemetry/proto/common/v1/common_marshaler.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,3 +301,86 @@ def write_to(self, out: bytearray) -> None:
301301
if self.dropped_attributes_count:
302302
out += b" "
303303
Varint.write_varint_u32(out, self.dropped_attributes_count)
304+
305+
306+
class EntityRef(MessageMarshaler):
307+
schema_url: str
308+
type: str
309+
310+
@property
311+
def id_keys(self) -> List[str]:
312+
if self._id_keys is None:
313+
self._id_keys = list()
314+
return self._id_keys
315+
316+
@property
317+
def description_keys(self) -> List[str]:
318+
if self._description_keys is None:
319+
self._description_keys = list()
320+
return self._description_keys
321+
322+
def __init__(
323+
self,
324+
schema_url: str = "",
325+
type: str = "",
326+
id_keys: List[str] = None,
327+
description_keys: List[str] = None,
328+
):
329+
self.schema_url: str = schema_url
330+
self.type: str = type
331+
self._id_keys: List[str] = id_keys
332+
self._description_keys: List[str] = description_keys
333+
334+
def calculate_size(self) -> int:
335+
size = 0
336+
if self.schema_url:
337+
v = self.schema_url.encode("utf-8")
338+
size += len(b"\n") + Varint.size_varint_u32(len(v)) + len(v)
339+
if self.type:
340+
v = self.type.encode("utf-8")
341+
size += len(b"\x12") + Varint.size_varint_u32(len(v)) + len(v)
342+
if self._id_keys:
343+
size = 0
344+
for s in self._id_keys:
345+
string_data = s.encode("utf-8")
346+
size += (
347+
len(b"\x1a")
348+
+ Varint.size_varint_u32(len(string_data))
349+
+ len(string_data)
350+
)
351+
size += size
352+
if self._description_keys:
353+
size = 0
354+
for s in self._description_keys:
355+
string_data = s.encode("utf-8")
356+
size += (
357+
len(b'"')
358+
+ Varint.size_varint_u32(len(string_data))
359+
+ len(string_data)
360+
)
361+
size += size
362+
return size
363+
364+
def write_to(self, out: bytearray) -> None:
365+
if self.schema_url:
366+
v = self.schema_url.encode("utf-8")
367+
out += b"\n"
368+
Varint.write_varint_u32(out, len(v))
369+
out += v
370+
if self.type:
371+
v = self.type.encode("utf-8")
372+
out += b"\x12"
373+
Varint.write_varint_u32(out, len(v))
374+
out += v
375+
if self._id_keys:
376+
for v in self._id_keys:
377+
out += b"\x1a"
378+
data = v.encode("utf-8")
379+
Varint.write_varint_u32(out, len(data))
380+
out += data
381+
if self._description_keys:
382+
for v in self._description_keys:
383+
out += b'"'
384+
data = v.encode("utf-8")
385+
Varint.write_varint_u32(out, len(data))
386+
out += data

src/snowflake/telemetry/_internal/opentelemetry/proto/logs/v1/logs_marshaler.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ def attributes(self) -> List[KeyValue]:
248248
trace_id: bytes
249249
span_id: bytes
250250
observed_time_unix_nano: int
251+
event_name: str
251252

252253
def __init__(
253254
self,
@@ -261,6 +262,7 @@ def __init__(
261262
trace_id: bytes = b"",
262263
span_id: bytes = b"",
263264
observed_time_unix_nano: int = 0,
265+
event_name: str = "",
264266
):
265267
self.time_unix_nano: int = time_unix_nano
266268
self.severity_number: SeverityNumber = severity_number
@@ -272,6 +274,7 @@ def __init__(
272274
self.trace_id: bytes = trace_id
273275
self.span_id: bytes = span_id
274276
self.observed_time_unix_nano: int = observed_time_unix_nano
277+
self.event_name: str = event_name
275278

276279
def calculate_size(self) -> int:
277280
size = 0
@@ -316,6 +319,9 @@ def calculate_size(self) -> int:
316319
)
317320
if self.observed_time_unix_nano:
318321
size += len(b"Y") + 8
322+
if self.event_name:
323+
v = self.event_name.encode("utf-8")
324+
size += len(b"b") + Varint.size_varint_u32(len(v)) + len(v)
319325
return size
320326

321327
def write_to(self, out: bytearray) -> None:
@@ -359,3 +365,8 @@ def write_to(self, out: bytearray) -> None:
359365
if self.observed_time_unix_nano:
360366
out += b"Y"
361367
out += struct.pack("<Q", self.observed_time_unix_nano)
368+
if self.event_name:
369+
v = self.event_name.encode("utf-8")
370+
out += b"b"
371+
Varint.write_varint_u32(out, len(v))
372+
out += v

0 commit comments

Comments
 (0)