Skip to content

Type json indent as optional #4402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

- Type indent parameter in to_json
([#4402](https://github.com/open-telemetry/opentelemetry-python/pull/4402))
- Tolerates exceptions when loading resource detectors via `OTEL_EXPERIMENTAL_RESOURCE_DETECTORS`
([#4373](https://github.com/open-telemetry/opentelemetry-python/pull/4373))
- opentelemetry-sdk: fix OTLP exporting of Histograms with explicit buckets advisory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def __eq__(self, other: object) -> bool:
return NotImplemented
return self.__dict__ == other.__dict__

def to_json(self, indent=4) -> str:
def to_json(self, indent: Optional[int] = 4) -> str:
return json.dumps(
{
"body": self.body,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class NumberDataPoint:
value: Union[int, float]
exemplars: Sequence[Exemplar] = field(default_factory=list)

def to_json(self, indent=4) -> str:
def to_json(self, indent: Optional[int] = 4) -> str:
return dumps(asdict(self), indent=indent)


Expand All @@ -59,7 +59,7 @@ class HistogramDataPoint:
max: float
exemplars: Sequence[Exemplar] = field(default_factory=list)

def to_json(self, indent=4) -> str:
def to_json(self, indent: Optional[int] = 4) -> str:
return dumps(asdict(self), indent=indent)


Expand Down Expand Up @@ -90,7 +90,7 @@ class ExponentialHistogramDataPoint:
max: float
exemplars: Sequence[Exemplar] = field(default_factory=list)

def to_json(self, indent=4) -> str:
def to_json(self, indent: Optional[int] = 4) -> str:
return dumps(asdict(self), indent=indent)


Expand All @@ -105,7 +105,7 @@ class ExponentialHistogram:
"opentelemetry.sdk.metrics.export.AggregationTemporality"
)

def to_json(self, indent=4) -> str:
def to_json(self, indent: Optional[int] = 4) -> str:
return dumps(
{
"data_points": [
Expand All @@ -129,7 +129,7 @@ class Sum:
)
is_monotonic: bool

def to_json(self, indent=4) -> str:
def to_json(self, indent: Optional[int] = 4) -> str:
return dumps(
{
"data_points": [
Expand All @@ -151,7 +151,7 @@ class Gauge:

data_points: Sequence[NumberDataPoint]

def to_json(self, indent=4) -> str:
def to_json(self, indent: Optional[int] = 4) -> str:
return dumps(
{
"data_points": [
Expand All @@ -173,7 +173,7 @@ class Histogram:
"opentelemetry.sdk.metrics.export.AggregationTemporality"
)

def to_json(self, indent=4) -> str:
def to_json(self, indent: Optional[int] = 4) -> str:
return dumps(
{
"data_points": [
Expand Down Expand Up @@ -203,7 +203,7 @@ class Metric:
unit: Optional[str]
data: DataT

def to_json(self, indent=4) -> str:
def to_json(self, indent: Optional[int] = 4) -> str:
return dumps(
{
"name": self.name,
Expand All @@ -223,7 +223,7 @@ class ScopeMetrics:
metrics: Sequence[Metric]
schema_url: str

def to_json(self, indent=4) -> str:
def to_json(self, indent: Optional[int] = 4) -> str:
return dumps(
{
"scope": loads(self.scope.to_json(indent=indent)),
Expand All @@ -245,7 +245,7 @@ class ResourceMetrics:
scope_metrics: Sequence[ScopeMetrics]
schema_url: str

def to_json(self, indent=4) -> str:
def to_json(self, indent: Optional[int] = 4) -> str:
return dumps(
{
"resource": loads(self.resource.to_json(indent=indent)),
Expand All @@ -265,7 +265,7 @@ class MetricsData:

resource_metrics: Sequence[ResourceMetrics]

def to_json(self, indent=4) -> str:
def to_json(self, indent: Optional[int] = 4) -> str:
return dumps(
{
"resource_metrics": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def __hash__(self) -> int:
f"{dumps(self._attributes.copy(), sort_keys=True)}|{self._schema_url}" # type: ignore
)

def to_json(self, indent: int = 4) -> str:
def to_json(self, indent: Optional[int] = 4) -> str:
attributes: MutableMapping[str, AttributeValue] = dict(
self._attributes
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ def instrumentation_info(self) -> Optional[InstrumentationInfo]:
def instrumentation_scope(self) -> Optional[InstrumentationScope]:
return self._instrumentation_scope

def to_json(self, indent: int = 4):
def to_json(self, indent: Optional[int] = 4):
parent_id = None
if self.parent is not None:
parent_id = f"0x{trace_api.format_span_id(self.parent.span_id)}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def name(self) -> str:
def attributes(self) -> Attributes:
return self._attributes

def to_json(self, indent=4) -> str:
def to_json(self, indent: Optional[int] = 4) -> str:
return dumps(
{
"name": self._name,
Expand Down