Skip to content

Commit

Permalink
Update encoder code
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jopel committed Nov 21, 2024
1 parent 6a65cbf commit bc62247
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 (
Expand Down Expand Up @@ -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

Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/snowflake-telemetry-test-utils/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
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",
"grpcio-tools >= 1.62.3",
"black >= 24.1.0",
"isort >= 5.12.0",
"hypothesis >= 6.0.0",
"google-benchmark",
],
packages=find_namespace_packages(
where='src'
Expand Down

0 comments on commit bc62247

Please sign in to comment.