fix(otlp-transformer): do not throw when deserializing empty JSON response (#5551)
This commit is contained in:
		
							parent
							
								
									6e15d69cb8
								
							
						
					
					
						commit
						37fe1e495b
					
				|  | @ -12,6 +12,8 @@ For notes on migrating to 2.x / 0.200.x see [the upgrade guide](doc/upgrade-to-2 | ||||||
| 
 | 
 | ||||||
| ### :bug: Bug Fixes | ### :bug: Bug Fixes | ||||||
| 
 | 
 | ||||||
|  | fix(otlp-transformer): do not throw when deserializing empty JSON response [#5551](https://github.com/open-telemetry/opentelemetry-js/pull/5551) @pichlermarc | ||||||
|  | 
 | ||||||
| ### :books: Documentation | ### :books: Documentation | ||||||
| 
 | 
 | ||||||
| ### :house: Internal | ### :house: Internal | ||||||
|  |  | ||||||
|  | @ -34,6 +34,9 @@ export const JsonLogsSerializer: ISerializer< | ||||||
|     return encoder.encode(JSON.stringify(request)); |     return encoder.encode(JSON.stringify(request)); | ||||||
|   }, |   }, | ||||||
|   deserializeResponse: (arg: Uint8Array) => { |   deserializeResponse: (arg: Uint8Array) => { | ||||||
|  |     if (arg.length === 0) { | ||||||
|  |       return {}; | ||||||
|  |     } | ||||||
|     const decoder = new TextDecoder(); |     const decoder = new TextDecoder(); | ||||||
|     return JSON.parse(decoder.decode(arg)) as IExportLogsServiceResponse; |     return JSON.parse(decoder.decode(arg)) as IExportLogsServiceResponse; | ||||||
|   }, |   }, | ||||||
|  |  | ||||||
|  | @ -30,6 +30,9 @@ export const JsonMetricsSerializer: ISerializer< | ||||||
|     return encoder.encode(JSON.stringify(request)); |     return encoder.encode(JSON.stringify(request)); | ||||||
|   }, |   }, | ||||||
|   deserializeResponse: (arg: Uint8Array) => { |   deserializeResponse: (arg: Uint8Array) => { | ||||||
|  |     if (arg.length === 0) { | ||||||
|  |       return {}; | ||||||
|  |     } | ||||||
|     const decoder = new TextDecoder(); |     const decoder = new TextDecoder(); | ||||||
|     return JSON.parse(decoder.decode(arg)) as IExportMetricsServiceResponse; |     return JSON.parse(decoder.decode(arg)) as IExportMetricsServiceResponse; | ||||||
|   }, |   }, | ||||||
|  |  | ||||||
|  | @ -31,6 +31,9 @@ export const JsonTraceSerializer: ISerializer< | ||||||
|     return encoder.encode(JSON.stringify(request)); |     return encoder.encode(JSON.stringify(request)); | ||||||
|   }, |   }, | ||||||
|   deserializeResponse: (arg: Uint8Array) => { |   deserializeResponse: (arg: Uint8Array) => { | ||||||
|  |     if (arg.length === 0) { | ||||||
|  |       return {}; | ||||||
|  |     } | ||||||
|     const decoder = new TextDecoder(); |     const decoder = new TextDecoder(); | ||||||
|     return JSON.parse(decoder.decode(arg)) as IExportTraceServiceResponse; |     return JSON.parse(decoder.decode(arg)) as IExportTraceServiceResponse; | ||||||
|   }, |   }, | ||||||
|  |  | ||||||
|  | @ -344,6 +344,12 @@ describe('Logs', () => { | ||||||
|         1 |         1 | ||||||
|       ); |       ); | ||||||
|     }); |     }); | ||||||
|  | 
 | ||||||
|  |     it('does not throw when deserializing an empty response', () => { | ||||||
|  |       assert.doesNotThrow(() => | ||||||
|  |         ProtobufLogsSerializer.deserializeResponse(new Uint8Array([])) | ||||||
|  |       ); | ||||||
|  |     }); | ||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
|   describe('JsonLogsSerializer', function () { |   describe('JsonLogsSerializer', function () { | ||||||
|  | @ -383,5 +389,11 @@ describe('Logs', () => { | ||||||
|         1 |         1 | ||||||
|       ); |       ); | ||||||
|     }); |     }); | ||||||
|  | 
 | ||||||
|  |     it('does not throw when deserializing an empty response', () => { | ||||||
|  |       assert.doesNotThrow(() => | ||||||
|  |         JsonLogsSerializer.deserializeResponse(new Uint8Array([])) | ||||||
|  |       ); | ||||||
|  |     }); | ||||||
|   }); |   }); | ||||||
| }); | }); | ||||||
|  |  | ||||||
|  | @ -858,6 +858,12 @@ describe('Metrics', () => { | ||||||
|         1 |         1 | ||||||
|       ); |       ); | ||||||
|     }); |     }); | ||||||
|  | 
 | ||||||
|  |     it('does not throw when deserializing an empty response', () => { | ||||||
|  |       assert.doesNotThrow(() => | ||||||
|  |         ProtobufMetricsSerializer.deserializeResponse(new Uint8Array([])) | ||||||
|  |       ); | ||||||
|  |     }); | ||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
|   describe('JsonMetricsSerializer', function () { |   describe('JsonMetricsSerializer', function () { | ||||||
|  | @ -929,5 +935,11 @@ describe('Metrics', () => { | ||||||
|         1 |         1 | ||||||
|       ); |       ); | ||||||
|     }); |     }); | ||||||
|  | 
 | ||||||
|  |     it('does not throw when deserializing an empty response', () => { | ||||||
|  |       assert.doesNotThrow(() => | ||||||
|  |         JsonMetricsSerializer.deserializeResponse(new Uint8Array([])) | ||||||
|  |       ); | ||||||
|  |     }); | ||||||
|   }); |   }); | ||||||
| }); | }); | ||||||
|  |  | ||||||
|  | @ -495,6 +495,12 @@ describe('Trace', () => { | ||||||
|         1 |         1 | ||||||
|       ); |       ); | ||||||
|     }); |     }); | ||||||
|  | 
 | ||||||
|  |     it('does not throw when deserializing an empty response', () => { | ||||||
|  |       assert.doesNotThrow(() => | ||||||
|  |         ProtobufTraceSerializer.deserializeResponse(new Uint8Array([])) | ||||||
|  |       ); | ||||||
|  |     }); | ||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
|   describe('JsonTracesSerializer', function () { |   describe('JsonTracesSerializer', function () { | ||||||
|  | @ -537,5 +543,11 @@ describe('Trace', () => { | ||||||
|         1 |         1 | ||||||
|       ); |       ); | ||||||
|     }); |     }); | ||||||
|  | 
 | ||||||
|  |     it('does not throw when deserializing an empty response', () => { | ||||||
|  |       assert.doesNotThrow(() => | ||||||
|  |         JsonTraceSerializer.deserializeResponse(new Uint8Array([])) | ||||||
|  |       ); | ||||||
|  |     }); | ||||||
|   }); |   }); | ||||||
| }); | }); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue