Skip to content
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

fix(backend): make span name query param #1591

Merged
merged 1 commit into from
Dec 11, 2024
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
4 changes: 2 additions & 2 deletions backend/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ func main() {
apps.PATCH(":id/rename", measure.RenameApp)
apps.POST(":id/shortFilters", measure.CreateShortFilters)
apps.GET(":id/spans/roots/names", measure.GetRootSpanNames)
apps.GET(":id/spans/:spanName/instances", measure.GetSpanInstances)
apps.GET(":id/spans/:spanName/plot", measure.GetSpanMetricsPlot)
apps.GET(":id/spans/instances", measure.GetSpanInstances)
apps.GET(":id/spans/plot", measure.GetSpanMetricsPlot)
apps.GET(":id/traces/:traceId", measure.GetTrace)
}

Expand Down
25 changes: 23 additions & 2 deletions backend/api/measure/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"math"
"net/http"
"net/url"
"sort"
"strings"
"time"
Expand Down Expand Up @@ -5275,7 +5276,17 @@ func GetSpanInstances(c *gin.Context) {
return
}

spanName := c.Param("spanName")
rawSpanName := c.Query("span_name")
if rawSpanName == "" {
c.JSON(http.StatusBadRequest, gin.H{"error": "Missing span_name query param"})
return
}

spanName, err := url.QueryUnescape(rawSpanName)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid span_name query param"})
return
}

af := filter.AppFilter{
AppID: id,
Expand Down Expand Up @@ -5397,7 +5408,17 @@ func GetSpanMetricsPlot(c *gin.Context) {
return
}

spanName := c.Param("spanName")
rawSpanName := c.Query("span_name")
if rawSpanName == "" {
c.JSON(http.StatusBadRequest, gin.H{"error": "Missing span_name query param"})
return
}

spanName, err := url.QueryUnescape(rawSpanName)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid span_name query param"})
return
}

af := filter.AppFilter{
AppID: id,
Expand Down
16 changes: 10 additions & 6 deletions docs/api/dashboard/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,12 @@ Find all the endpoints, resources and detailed documentation for Measure Dashboa
- [Authorization \& Content Type](#authorization--content-type-21)
- [Response Body](#response-body-21)
- [Status Codes \& Troubleshooting](#status-codes--troubleshooting-21)
- [GET `/apps/:id/spans/:spanName/instances`](#get-appsidspanspannameinstances)
- [GET `/apps/:id/spans/instances`](#get-appsidspansinstances)
- [Usage Notes](#usage-notes-22)
- [Authorization \& Content Type](#authorization--content-type-22)
- [Response Body](#response-body-22)
- [Status Codes \& Troubleshooting](#status-codes--troubleshooting-22)
- [GET `/apps/:id/spans/:spanName/plot`](#get-appsidspansspannameplot)
- [GET `/apps/:id/spans/plot`](#get-appsidspansplot)
- [Usage Notes](#usage-notes-23)
- [Authorization \& Content Type](#authorization--content-type-23)
- [Response Body](#response-body-23)
Expand Down Expand Up @@ -219,8 +219,8 @@ Find all the endpoints, resources and detailed documentation for Measure Dashboa
- [**PATCH `/apps/:id/settings`**](#patch-appsidsettings) - Update an app's settings.
- [**POST `/apps/:id/shortFilters`**](#post-appsidshortfilters) - Create a shortcode to represent a combination of various app filters.
- [**GET `/apps/:id/spans/roots/names`**](#get-appsidspansrootsnames) - Fetch an app's root span names list with optional filters.
- [**GET `/apps/:id/spans/:spanName/instances`**](#get-appsidspanspannameinstances) - Fetch an span's list of instances with optional filters.
- [**GET `/apps/:id/spans/:spanName/plot`**](#get-appsidspansspannameplot) - Fetch an span's metrics plot with optional filters.
- [**GET `/apps/:id/spans/instances`**](#get-appsidspansinstances) - Fetch an span's list of instances with optional filters.
- [**GET `/apps/:id/spans/plot`**](#get-appsidspansplot) - Fetch an span's metrics plot with optional filters.
- [**GET `/apps/:id/traces/:traceId`**](#get-appsidtracestraceid) - Fetch a trace.

### GET `/apps/:id/journey`
Expand Down Expand Up @@ -3603,14 +3603,16 @@ List of HTTP status codes for success and failures.

</details>

### GET `/apps/:id/spans/:spanName/instances`
### GET `/apps/:id/spans/instances`

Fetch an span's list of instances with optional filters.

#### Usage Notes

- App's UUID must be passed in the URI
- Span name for which instances list is being fetched must be passed as a query param
- Accepted query parameters
- `span_name` (_required_) - Name of the span for which instances list is being fetched.
- `from` (_optional_) - ISO8601 timestamp to include sessions after this time.
- `to` (_optional_) - ISO8601 timestamp to include sessions before this time.
- `versions` (_optional_) - List of comma separated version identifier strings to return only matching sessions.
Expand Down Expand Up @@ -3740,14 +3742,16 @@ List of HTTP status codes for success and failures.

</details>

### GET `/apps/:id/spans/:spanName/plot`
### GET `/apps/:id/spans/plot`

Fetch an span's metrics plot with optional filters.

#### Usage Notes

- App's UUID must be passed in the URI
- Span name for which metrics plot is being fetched must be passed as a query param
- Accepted query parameters
- `span_name` (_required_) - Name of the span for which metrics plot is being fetched.
- `from` (_optional_) - ISO8601 timestamp to include sessions after this time.
- `to` (_optional_) - ISO8601 timestamp to include sessions before this time.
- `versions` (_optional_) - List of comma separated version identifier strings to return only matching sessions.
Expand Down
9 changes: 7 additions & 2 deletions frontend/dashboard/app/api/api_calls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,11 @@ async function applyGenericFiltersToUrl(url: string, filters: Filters, keyId: st
searchParams.append('anr', '1')
}

// Append span name if needed
if (filters.rootSpanName !== "") {
searchParams.append('span_name', encodeURIComponent(filters.rootSpanName))
}

// Append span statuses if needed
if (filters.spanStatuses.length > 0) {
filters.spanStatuses.forEach((v) => {
Expand Down Expand Up @@ -956,7 +961,7 @@ export const fetchRootSpanNamesFromServer = async (selectedApp: typeof emptyApp,
export const fetchSpanInstancesFromServer = async (filters: Filters, limit: number, offset: number, router: AppRouterInstance) => {
const origin = process.env.NEXT_PUBLIC_API_BASE_URL

var url = `${origin}/apps/${filters.app.id}/spans/${filters.rootSpanName}/instances?`
var url = `${origin}/apps/${filters.app.id}/spans/instances?`

url = await applyGenericFiltersToUrl(url, filters, null, null, limit, offset)

Expand All @@ -979,7 +984,7 @@ export const fetchSpanInstancesFromServer = async (filters: Filters, limit: numb
export const fetchSpanMetricsPlotFromServer = async (filters: Filters, router: AppRouterInstance) => {
const origin = process.env.NEXT_PUBLIC_API_BASE_URL

var url = `${origin}/apps/${filters.app.id}/spans/${filters.rootSpanName}/plot?`
var url = `${origin}/apps/${filters.app.id}/spans/plot?`

url = await applyGenericFiltersToUrl(url, filters, null, null, null, null)

Expand Down
Loading