From bc6224741ed279ff4f43ab921d05a1de7b9b1617 Mon Sep 17 00:00:00 2001 From: Jeevan Singh Opel Date: Thu, 21 Nov 2024 17:02:35 +0000 Subject: [PATCH] Update encoder code --- .../exporter/otlp/proto/logs/__init__.py | 4 ++-- .../exporter/otlp/proto/metrics/__init__.py | 4 ++-- .../exporter/otlp/proto/traces/__init__.py | 4 ++-- .../otlp/proto/common/_internal/__init__.py | 12 ++++++------ .../common/_internal/_log_encoder/__init__.py | 6 +++--- .../_internal/metrics_encoder/__init__.py | 17 ++++------------- .../common/_internal/trace_encoder/__init__.py | 12 ++++++------ tests/snowflake-telemetry-test-utils/setup.py | 2 ++ 8 files changed, 27 insertions(+), 34 deletions(-) diff --git a/src/snowflake/telemetry/_internal/exporter/otlp/proto/logs/__init__.py b/src/snowflake/telemetry/_internal/exporter/otlp/proto/logs/__init__.py index 3214e3e..9361c20 100644 --- a/src/snowflake/telemetry/_internal/exporter/otlp/proto/logs/__init__.py +++ b/src/snowflake/telemetry/_internal/exporter/otlp/proto/logs/__init__.py @@ -21,10 +21,10 @@ import opentelemetry.sdk.util.instrumentation as otel_instrumentation import opentelemetry.sdk._logs._internal as _logs_internal -from opentelemetry.exporter.otlp.proto.common._log_encoder import ( +from snowflake.telemetry._internal.opentelemetry.exporter.otlp.proto.common._log_encoder import ( encode_logs, ) -from opentelemetry.proto.logs.v1.logs_pb2 import LogsData +from snowflake.telemetry._internal.opentelemetry.proto.logs.v1.logs_marshaler import LogsData from opentelemetry.sdk.resources import Resource from opentelemetry.sdk._logs import export from opentelemetry.sdk import _logs diff --git a/src/snowflake/telemetry/_internal/exporter/otlp/proto/metrics/__init__.py b/src/snowflake/telemetry/_internal/exporter/otlp/proto/metrics/__init__.py index 46291d1..91ff137 100644 --- a/src/snowflake/telemetry/_internal/exporter/otlp/proto/metrics/__init__.py +++ b/src/snowflake/telemetry/_internal/exporter/otlp/proto/metrics/__init__.py @@ -17,10 +17,10 @@ from typing import Dict import opentelemetry -from opentelemetry.exporter.otlp.proto.common.metrics_encoder import ( +from snowflake.telemetry._internal.opentelemetry.exporter.otlp.proto.common.metrics_encoder import ( encode_metrics, ) -from opentelemetry.proto.metrics.v1.metrics_pb2 import MetricsData as PB2MetricsData +from snowflake.telemetry._internal.opentelemetry.proto.metrics.v1.metrics_marshaler import MetricsData as PB2MetricsData from opentelemetry.sdk.metrics.export import ( AggregationTemporality, MetricExportResult, diff --git a/src/snowflake/telemetry/_internal/exporter/otlp/proto/traces/__init__.py b/src/snowflake/telemetry/_internal/exporter/otlp/proto/traces/__init__.py index 7c877aa..41aa617 100644 --- a/src/snowflake/telemetry/_internal/exporter/otlp/proto/traces/__init__.py +++ b/src/snowflake/telemetry/_internal/exporter/otlp/proto/traces/__init__.py @@ -16,10 +16,10 @@ import abc import typing -from opentelemetry.exporter.otlp.proto.common.trace_encoder import ( +from snowflake.telemetry._internal.opentelemetry.exporter.otlp.proto.common.trace_encoder import ( encode_spans, ) -from opentelemetry.proto.trace.v1.trace_pb2 import TracesData +from snowflake.telemetry._internal.opentelemetry.proto.trace.v1.trace_marshaler import TracesData from opentelemetry.sdk.trace import ReadableSpan from opentelemetry.sdk.trace.export import ( SpanExportResult, 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 099a01b..b07bad4 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 @@ -28,18 +28,18 @@ ) from opentelemetry.sdk.util.instrumentation import InstrumentationScope -from snowflake.telemetry._internal.opentelemetry.proto.common.v1 import ( +from snowflake.telemetry._internal.opentelemetry.proto.common.v1.common_marshaler import ( InstrumentationScope as PB2InstrumentationScope, ) -from snowflake.telemetry._internal.opentelemetry.proto.resource.v1 import ( +from snowflake.telemetry._internal.opentelemetry.proto.resource.v1.resource_marshaler import ( Resource as PB2Resource, ) -from snowflake.telemetry._internal.opentelemetry.proto.common.v1 import AnyValue as PB2AnyValue -from snowflake.telemetry._internal.opentelemetry.proto.common.v1 import KeyValue as PB2KeyValue -from snowflake.telemetry._internal.opentelemetry.proto.common.v1 import ( +from snowflake.telemetry._internal.opentelemetry.proto.common.v1.common_marshaler import AnyValue as PB2AnyValue +from snowflake.telemetry._internal.opentelemetry.proto.common.v1.common_marshaler import KeyValue as PB2KeyValue +from snowflake.telemetry._internal.opentelemetry.proto.common.v1.common_marshaler import ( KeyValueList as PB2KeyValueList, ) -from snowflake.telemetry._internal.opentelemetry.proto.common.v1 import ( +from snowflake.telemetry._internal.opentelemetry.proto.common.v1.common_marshaler import ( ArrayValue as PB2ArrayValue, ) from opentelemetry.sdk.trace import Resource 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 0724a03..ca38cf4 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 @@ -22,14 +22,14 @@ _encode_value, _encode_attributes, ) -from snowflake.telemetry._internal.opentelemetry.proto.collector.logs.v1 import ( +from snowflake.telemetry._internal.opentelemetry.proto.collector.logs.v1.logs_service_marshaler import ( ExportLogsServiceRequest, ) -from snowflake.telemetry._internal.opentelemetry.proto.logs.v1 import ( +from snowflake.telemetry._internal.opentelemetry.proto.logs.v1.logs_marshaler import ( ScopeLogs, ResourceLogs, ) -from snowflake.telemetry._internal.opentelemetry.proto.logs.v1 import LogRecord as PB2LogRecord +from snowflake.telemetry._internal.opentelemetry.proto.logs.v1.logs_marshaler import LogRecord as PB2LogRecord from opentelemetry.sdk._logs import LogData 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 023ab0d..481aacd 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 @@ -35,11 +35,11 @@ from opentelemetry.sdk.metrics.export import ( AggregationTemporality, ) -from snowflake.telemetry._internal.opentelemetry.proto.collector.metrics.v1 import ( +from snowflake.telemetry._internal.opentelemetry.proto.collector.metrics.v1.metrics_service_marshaler import ( ExportMetricsServiceRequest, ) -from snowflake.telemetry._internal.opentelemetry.proto.common.v1 import InstrumentationScope -import snowflake.telemetry._internal.opentelemetry.proto.metrics.v1 as pb2 +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 opentelemetry.sdk.metrics.export import ( MetricsData, Gauge, @@ -48,7 +48,7 @@ ExponentialHistogram as ExponentialHistogramType, ) from typing import Dict -from snowflake.telemetry._internal.opentelemetry.proto.resource.v1 import ( +from snowflake.telemetry._internal.opentelemetry.proto.resource.v1.resource_marshaler import ( Resource as PB2Resource, ) from opentelemetry.sdk.environment_variables import ( @@ -199,7 +199,6 @@ def encode_metrics(data: MetricsData) -> ExportMetricsServiceRequest: version=instrumentation_scope.version, ) ) - pb2_scope_metrics.metrics = [] scope_metrics_dict[instrumentation_scope] = pb2_scope_metrics @@ -211,8 +210,6 @@ def encode_metrics(data: MetricsData) -> ExportMetricsServiceRequest: ) if isinstance(metric.data, Gauge): - pb2_metric.gauge = pb2.Gauge() - pb2_metric.gauge.data_points = [] for data_point in metric.data.data_points: pt = pb2.NumberDataPoint( attributes=_encode_attributes( @@ -227,8 +224,6 @@ def encode_metrics(data: MetricsData) -> ExportMetricsServiceRequest: pb2_metric.gauge.data_points.append(pt) elif isinstance(metric.data, HistogramType): - pb2_metric.histogram = pb2.Histogram() - pb2_metric.histogram.data_points = [] for data_point in metric.data.data_points: pt = pb2.HistogramDataPoint( attributes=_encode_attributes( @@ -251,8 +246,6 @@ def encode_metrics(data: MetricsData) -> ExportMetricsServiceRequest: pb2_metric.histogram.data_points.append(pt) elif isinstance(metric.data, Sum): - pb2_metric.sum = pb2.Sum() - pb2_metric.sum.data_points = [] for data_point in metric.data.data_points: pt = pb2.NumberDataPoint( attributes=_encode_attributes( @@ -277,8 +270,6 @@ def encode_metrics(data: MetricsData) -> ExportMetricsServiceRequest: pb2_metric.sum.data_points.append(pt) elif isinstance(metric.data, ExponentialHistogramType): - pb2_metric.exponential_histogram = pb2.ExponentialHistogram() - pb2_metric.exponential_histogram.data_points = [] for data_point in metric.data.data_points: if data_point.positive.bucket_counts: 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 dc9dfeb..84f00fb 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 @@ -23,16 +23,16 @@ _encode_span_id, _encode_trace_id, ) -from snowflake.telemetry._internal.opentelemetry.proto.collector.trace.v1 import ( +from snowflake.telemetry._internal.opentelemetry.proto.collector.trace.v1.trace_service_marshaler import ( ExportTraceServiceRequest as PB2ExportTraceServiceRequest, ) -from snowflake.telemetry._internal.opentelemetry.proto.trace.v1 import ( +from snowflake.telemetry._internal.opentelemetry.proto.trace.v1.trace_marshaler import ( ResourceSpans as PB2ResourceSpans, ) -from snowflake.telemetry._internal.opentelemetry.proto.trace.v1 import ScopeSpans as PB2ScopeSpans -from snowflake.telemetry._internal.opentelemetry.proto.trace.v1 import Span as PB2SPan -from snowflake.telemetry._internal.opentelemetry.proto.trace.v1 import SpanFlags as PB2SpanFlags -from snowflake.telemetry._internal.opentelemetry.proto.trace.v1 import Status as PB2Status +from snowflake.telemetry._internal.opentelemetry.proto.trace.v1.trace_marshaler import ScopeSpans as PB2ScopeSpans +from snowflake.telemetry._internal.opentelemetry.proto.trace.v1.trace_marshaler import Span as PB2SPan +from snowflake.telemetry._internal.opentelemetry.proto.trace.v1.trace_marshaler import SpanFlags as PB2SpanFlags +from snowflake.telemetry._internal.opentelemetry.proto.trace.v1.trace_marshaler import Status as PB2Status from opentelemetry.sdk.trace import Event, ReadableSpan from opentelemetry.trace import Link, SpanKind from opentelemetry.trace.span import SpanContext, Status, TraceState diff --git a/tests/snowflake-telemetry-test-utils/setup.py b/tests/snowflake-telemetry-test-utils/setup.py index 0511b8e..6254955 100644 --- a/tests/snowflake-telemetry-test-utils/setup.py +++ b/tests/snowflake-telemetry-test-utils/setup.py @@ -15,6 +15,7 @@ description=DESCRIPTION, long_description=LONG_DESCRIPTION, install_requires=[ + "opentelemetry-exporter-otlp-proto-common == 1.26.0", "pytest >= 7.0.0", "snowflake-telemetry-python == 0.6.0.dev", "Jinja2 == 3.1.4", @@ -22,6 +23,7 @@ "black >= 24.1.0", "isort >= 5.12.0", "hypothesis >= 6.0.0", + "google-benchmark", ], packages=find_namespace_packages( where='src'