Skip to content
New issue

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

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

Already on GitHub? # to your account

- Add strict validation for span fields (traceID, spanID, operationNa… #2677

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

rohitlohar45
Copy link

@rohitlohar45 rohitlohar45 commented Mar 2, 2025

Here's a fixed version of the PR description:

Which problem is this PR solving?

Description of the changes

  • Add proper error handling for invalid JSON formats

How was this change tested?

  • Tested with the exact OpenTelemetry span format from the issue
  • Validated with JSON generated from hotrod traces
  • Improved error messaging in the client UI for better feedback

Checklist

…me, etc)

- Add process object validation to ensure serviceName exists
- Improve validation of process references in spans
- Handle both Jaeger and OTLP trace formats
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @rohitlohar45, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request addresses issue #6517 by adding strict validation for span fields, improving error handling, and supporting OpenTelemetry span JSON format uploads. The changes include converting OTel spans to OTLP format during processing and handling different trace format types (Jaeger, OTLP, and single OTel spans). The changes primarily affect the readJsonFile.tsx file in the jaeger-ui package.

Highlights

  • OTel Span Support: Adds support for uploading OpenTelemetry span JSON format and converts them to OTLP format for processing.
  • Strict Validation: Improves validation for span and process properties to ensure data integrity.
  • Error Handling: Adds proper error handling for invalid JSON formats, providing better feedback in the client UI.
  • Trace Format Handling: Handles different trace format types, including Jaeger, OTLP, and single OTel spans.

Changelog

Click here to see the changelog
  • packages/jaeger-ui/src/utils/readJsonFile.tsx
    • Added validateSpan function to validate span fields (traceID, spanID, operationName, startTime, duration, processID). Lines 33-43
    • Added validateProcess function to validate process properties (serviceName). Lines 45-51
    • Added isOTelSpan function to check if an object is an OpenTelemetry span based on the presence of context.trace_id and context.span_id. Lines 54-62
    • Added convertOTelSpanToOTLP function to convert an OTel span to OTLP format. Lines 65-97
    • Added validateJaegerTrace function to validate Jaeger trace format, including support for OTel spans and resourceSpans. Lines 100-120
    • Added validateSingleTrace function to validate a single Jaeger trace, checking for traceID, spans, and processes. Lines 122-139
    • Improved error handling when parsing JSON, providing a more informative error message. Line 156
    • Added validation for Jaeger and OTLP trace formats, rejecting invalid formats. Line 162
    • Conversion of OTel spans to OTLP format when detected. Line 167
    • Updated error message when converting traces to Jaeger format. Line 185
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


Did you know?

The term 'telemetry' originates from the Greek roots 'tele' (remote) and 'metron' (measure).

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request introduces validation for span fields and adds support for OpenTelemetry span JSON format upload, converting them to OTLP format during processing. It also improves error handling for invalid JSON formats and handles different trace format types. Overall, the changes seem well-structured and address the issue mentioned in the PR description. However, there are a few areas where improvements can be made to enhance code clarity and maintainability.

Merge Readiness

The changes introduced by this pull request enhance the application's ability to handle various trace formats and improve data validation. While the code appears functional, addressing the suggestions related to error message clarity and code structure would further improve the quality and maintainability of the codebase. I am unable to directly approve this pull request, and recommend that others review and approve this code before merging. Given the absence of CRITICAL or HIGH severity issues, the pull request is a good candidate for merging once the feedback is addressed.

@yurishkuro
Copy link
Member

Add proper error handling for invalid JSON formats

this was the only change required per the issue. The UI already handles different input formats.

@rohitlohar45
Copy link
Author

@yurishkuro Thank you for the clarification. I've adjusted my implementation to focus specifically on the error handling for invalid JSON formats as you mentioned. The revised code now properly handles the error case that was causing the "Cannot read properties of undefined (reading 'map')" exception.

Copy link
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry but I don't see why we need these changes. The code can already recognize valid formats, that part requires no changes. What is the root cause of the issue when invalid format is uploaded?

@rohitlohar45
Copy link
Author

@yurishkuro
The root cause of this problem is that when uploading a single-span OpenTelemetry JSON format (such as in the issue filed as far as I understood), the existing code correctly parses but fails to validate it before passing it to loadJsonDone() function.

When loadJsonDone() attempts to parse this data, it tries to map over a property that is not present in this structure with properties (probably looking for a structure that has a data array), and throws the TypeError: Cannot read properties of undefined (reading 'map').

In my fix I added verification to catch this particular instance and reject with an appropriate error message rather than allowing the not supported format to be send to loadJsonDone(). This avoids the runtime error while not changing the existing format handling for correct inputs.

@yurishkuro
Copy link
Member

None of the so-called validations are validating the whole structure, so there can be an issue deeper in the structure which may still throw exception somewhere. The objective of the ticket was to ensure that such exceptions are still caught and displayed on the screen, not let it hang with a spinner.

@rohitlohar45
Copy link
Author

So do I need to check for that recursively? Because for for large trace files, deep validation might impact performance.

@yurishkuro
Copy link
Member

We don't need to validate anything, we need to catch exceptions and display them.

@rohitlohar45
Copy link
Author

Understood, I added the try catch block to catch the exceptions if any in the loadJsonDone function, it worked and was displaying the error for non supported JSON

@rohitlohar45
Copy link
Author

@yurishkuro any issues with the changes?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: upload in Jaeger UI appears to be broken
2 participants