Skip to content

Commit c44df70

Browse files
NN---lzchenemdneto
authored
Type json indent as optional (#4402)
* Type json indent as optional * Fix * Update changelog * Update changelog * Update CHANGELOG.md --------- Co-authored-by: Leighton Chen <[email protected]> Co-authored-by: Emídio Neto <[email protected]>
1 parent ac7329c commit c44df70

File tree

6 files changed

+17
-15
lines changed

6 files changed

+17
-15
lines changed

Diff for: CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
- Type indent parameter in to_json
11+
([#4402](https://github.com/open-telemetry/opentelemetry-python/pull/4402))
1012
- Tolerates exceptions when loading resource detectors via `OTEL_EXPERIMENTAL_RESOURCE_DETECTORS`
1113
([#4373](https://github.com/open-telemetry/opentelemetry-python/pull/4373))
1214
- opentelemetry-sdk: fix OTLP exporting of Histograms with explicit buckets advisory

Diff for: opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def __eq__(self, other: object) -> bool:
217217
return NotImplemented
218218
return self.__dict__ == other.__dict__
219219

220-
def to_json(self, indent=4) -> str:
220+
def to_json(self, indent: Optional[int] = 4) -> str:
221221
return json.dumps(
222222
{
223223
"body": self.body,

Diff for: opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/point.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class NumberDataPoint:
3838
value: Union[int, float]
3939
exemplars: Sequence[Exemplar] = field(default_factory=list)
4040

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

4444

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

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

6565

@@ -90,7 +90,7 @@ class ExponentialHistogramDataPoint:
9090
max: float
9191
exemplars: Sequence[Exemplar] = field(default_factory=list)
9292

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

9696

@@ -105,7 +105,7 @@ class ExponentialHistogram:
105105
"opentelemetry.sdk.metrics.export.AggregationTemporality"
106106
)
107107

108-
def to_json(self, indent=4) -> str:
108+
def to_json(self, indent: Optional[int] = 4) -> str:
109109
return dumps(
110110
{
111111
"data_points": [
@@ -129,7 +129,7 @@ class Sum:
129129
)
130130
is_monotonic: bool
131131

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

152152
data_points: Sequence[NumberDataPoint]
153153

154-
def to_json(self, indent=4) -> str:
154+
def to_json(self, indent: Optional[int] = 4) -> str:
155155
return dumps(
156156
{
157157
"data_points": [
@@ -173,7 +173,7 @@ class Histogram:
173173
"opentelemetry.sdk.metrics.export.AggregationTemporality"
174174
)
175175

176-
def to_json(self, indent=4) -> str:
176+
def to_json(self, indent: Optional[int] = 4) -> str:
177177
return dumps(
178178
{
179179
"data_points": [
@@ -203,7 +203,7 @@ class Metric:
203203
unit: Optional[str]
204204
data: DataT
205205

206-
def to_json(self, indent=4) -> str:
206+
def to_json(self, indent: Optional[int] = 4) -> str:
207207
return dumps(
208208
{
209209
"name": self.name,
@@ -223,7 +223,7 @@ class ScopeMetrics:
223223
metrics: Sequence[Metric]
224224
schema_url: str
225225

226-
def to_json(self, indent=4) -> str:
226+
def to_json(self, indent: Optional[int] = 4) -> str:
227227
return dumps(
228228
{
229229
"scope": loads(self.scope.to_json(indent=indent)),
@@ -245,7 +245,7 @@ class ResourceMetrics:
245245
scope_metrics: Sequence[ScopeMetrics]
246246
schema_url: str
247247

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

266266
resource_metrics: Sequence[ResourceMetrics]
267267

268-
def to_json(self, indent=4) -> str:
268+
def to_json(self, indent: Optional[int] = 4) -> str:
269269
return dumps(
270270
{
271271
"resource_metrics": [

Diff for: opentelemetry-sdk/src/opentelemetry/sdk/resources/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ def __hash__(self) -> int:
297297
f"{dumps(self._attributes.copy(), sort_keys=True)}|{self._schema_url}" # type: ignore
298298
)
299299

300-
def to_json(self, indent: int = 4) -> str:
300+
def to_json(self, indent: Optional[int] = 4) -> str:
301301
attributes: MutableMapping[str, AttributeValue] = dict(
302302
self._attributes
303303
)

Diff for: opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ def instrumentation_info(self) -> Optional[InstrumentationInfo]:
483483
def instrumentation_scope(self) -> Optional[InstrumentationScope]:
484484
return self._instrumentation_scope
485485

486-
def to_json(self, indent: int = 4):
486+
def to_json(self, indent: Optional[int] = 4):
487487
parent_id = None
488488
if self.parent is not None:
489489
parent_id = f"0x{trace_api.format_span_id(self.parent.span_id)}"

Diff for: opentelemetry-sdk/src/opentelemetry/sdk/util/instrumentation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def name(self) -> str:
153153
def attributes(self) -> Attributes:
154154
return self._attributes
155155

156-
def to_json(self, indent=4) -> str:
156+
def to_json(self, indent: Optional[int] = 4) -> str:
157157
return dumps(
158158
{
159159
"name": self._name,

0 commit comments

Comments
 (0)