Skip to content

Commit 73f414e

Browse files
authored
Type json indent as optional
1 parent c6fab7d commit 73f414e

File tree

6 files changed

+17
-17
lines changed

6 files changed

+17
-17
lines changed

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,

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": [

opentelemetry-sdk/src/opentelemetry/sdk/resources/__init__.py

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

293-
def to_json(self, indent: int = 4) -> str:
293+
def to_json(self, indent: Optional[int] = 4) -> str:
294294
attributes: MutableMapping[str, AttributeValue] = dict(
295295
self._attributes
296296
)

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)}"

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,

opentelemetry-sdk/tests/logs/test_log_record.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def test_log_record_to_json(self):
4545
"schema_url": "",
4646
},
4747
},
48-
indent=4,
48+
indent: Optional[int] = 4,
4949
)
5050
actual = LogRecord(
5151
timestamp=0,
@@ -54,7 +54,7 @@ def test_log_record_to_json(self):
5454
resource=Resource({"service.name": "foo"}),
5555
)
5656

57-
self.assertEqual(expected, actual.to_json(indent=4))
57+
self.assertEqual(expected, actual.to_json(indent: Optional[int] = 4))
5858
self.assertEqual(
5959
actual.to_json(indent=None),
6060
'{"body": "a log line", "severity_number": null, "severity_text": null, "attributes": null, "dropped_attributes": 0, "timestamp": "1970-01-01T00:00:00.000000Z", "observed_timestamp": "1970-01-01T00:00:00.000000Z", "trace_id": "", "span_id": "", "trace_flags": null, "resource": {"attributes": {"service.name": "foo"}, "schema_url": ""}}',

0 commit comments

Comments
 (0)