Skip to content

Commit 6d037b4

Browse files
Add service_name and deployment_environment filters to exceptions tool (#57)
- Add service_name parameter to filter exceptions by service - Add deployment_environment parameter to filter by resource attributes - Update tool description and README documentation - Add godotenv support for local .env file configuration This enables more precise exception filtering for debugging specific services and environments. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <[email protected]>
1 parent 9aecd95 commit 6d037b4

File tree

6 files changed

+30
-7
lines changed

6 files changed

+30
-7
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ Parameters:
7373
HH:MM:SS). Leave empty to use lookback_minutes.
7474
- `end_time_iso` (string, optional): End time in ISO format (YYYY-MM-DD
7575
HH:MM:SS). Leave empty to default to current time.
76+
- `service_name` (string, optional): Filter exceptions by service name (e.g., api-service).
7677
- `span_name` (string, optional): Name of the span to filter by.
78+
- `deployment_environment` (string, optional): Filter exceptions by deployment environment from resource attributes (e.g., production, staging).
7779

7880
### get_service_summary
7981

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ require (
1616
github.com/google/jsonschema-go v0.2.1-0.20250825175020-748c325cec76 // indirect
1717
github.com/google/uuid v1.6.0 // indirect
1818
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2 // indirect
19+
github.com/joho/godotenv v1.5.1 // indirect
1920
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
2021
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
2122
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.63.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
1919
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
2020
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2 h1:8Tjv8EJ+pM1xP8mK6egEbD1OgnVTyacbefKhmbLhIhU=
2121
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2/go.mod h1:pkJQ2tZHJ0aFOVEEot6oZmaVEZcRme73eIFmhiVuRWs=
22+
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
23+
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
2224
github.com/last9/mcp-go-sdk v0.0.0-20251015185513-1886c8f0ff86 h1:NEWU12yyDqF2LMA37y9X4fn3Y3Y5FGS+JeW+Ngir3Yo=
2325
github.com/last9/mcp-go-sdk v0.0.0-20251015185513-1886c8f0ff86/go.mod h1:GWkOantadjGvDdTpbuLjmJhmD2G0U9AWQgnXZJDaPrE=
2426
github.com/modelcontextprotocol/go-sdk v0.3.1 h1:0z04yIPlSwTluuelCBaL+wUag4YeflIU2Fr4Icb7M+o=

internal/telemetry/traces/description.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
package traces
22

33
const GetExceptionsDescription = `
4-
Get server side exceptions over the given time range.
4+
Get server side exceptions over the given time range.
55
Includes the exception type, message, stack trace, service name, trace ID and span attributes.
6-
6+
77
limit: (Optional) The maximum number of exceptions to return. Defaults to 20.
88
lookback_minutes: (Recommended) Number of minutes to look back from now. Use this for relative time ranges.
99
start_time_iso: (Optional) The start time to get the data from. Leave empty to use lookback_minutes instead.
1010
end_time_iso: (Optional) The end time to get the data from. Leave empty to default to current time.
11+
service_name: (Optional) Filter exceptions by service name (e.g. api-service).
1112
span_name: (Optional) The name of the span to get the data for. This is often the API endpoint name or controller name.
13+
deployment_environment: (Optional) Filter exceptions by deployment environment from resource attributes (e.g. production, staging).
1214
`
1315

1416
const GetServiceGraphDescription = `

internal/telemetry/traces/exception.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ import (
1818

1919
// GetExceptionsArgs defines the input structure for getting exceptions
2020
type GetExceptionsArgs struct {
21-
Limit float64 `json:"limit,omitempty" jsonschema:"Maximum number of exceptions to return (default: 20, range: 1-1000)"`
22-
LookbackMinutes float64 `json:"lookback_minutes,omitempty" jsonschema:"Number of minutes to look back from current time (default: 60, range: 1-10080)"`
23-
StartTimeISO string `json:"start_time_iso,omitempty" jsonschema:"Start time in ISO8601 format (e.g. 2024-06-01T12:00:00Z)"`
24-
EndTimeISO string `json:"end_time_iso,omitempty" jsonschema:"End time in ISO8601 format (e.g. 2024-06-01T13:00:00Z)"`
25-
SpanName string `json:"span_name,omitempty" jsonschema:"Filter exceptions by span name (e.g. user_service)"`
21+
Limit float64 `json:"limit,omitempty" jsonschema:"Maximum number of exceptions to return (default: 20, range: 1-1000)"`
22+
LookbackMinutes float64 `json:"lookback_minutes,omitempty" jsonschema:"Number of minutes to look back from current time (default: 60, range: 1-10080)"`
23+
StartTimeISO string `json:"start_time_iso,omitempty" jsonschema:"Start time in ISO8601 format (e.g. 2024-06-01T12:00:00Z)"`
24+
EndTimeISO string `json:"end_time_iso,omitempty" jsonschema:"End time in ISO8601 format (e.g. 2024-06-01T13:00:00Z)"`
25+
ServiceName string `json:"service_name,omitempty" jsonschema:"Filter exceptions by service name (e.g. api-service)"`
26+
SpanName string `json:"span_name,omitempty" jsonschema:"Filter exceptions by span name (e.g. user_service)"`
27+
DeploymentEnvironment string `json:"deployment_environment,omitempty" jsonschema:"Filter exceptions by deployment environment from resource attributes (e.g. production, staging)"`
2628
}
2729

2830
// NewGetExceptionsHandler creates a handler for getting exceptions
@@ -64,10 +66,18 @@ func NewGetExceptionsHandler(client *http.Client, cfg models.Config) func(contex
6466
q.Set("end", strconv.FormatInt(endTime.Unix(), 10))
6567
q.Set("limit", strconv.Itoa(limit))
6668

69+
if args.ServiceName != "" {
70+
q.Set("service_name", args.ServiceName)
71+
}
72+
6773
if args.SpanName != "" {
6874
q.Set("span_name", args.SpanName)
6975
}
7076

77+
if args.DeploymentEnvironment != "" {
78+
q.Set("deployment_environment", args.DeploymentEnvironment)
79+
}
80+
7181
u.RawQuery = q.Encode()
7282

7383
// Create request

main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,19 @@ import (
99
"last9-mcp/internal/models"
1010
"last9-mcp/internal/utils"
1111

12+
"github.com/joho/godotenv"
1213
last9mcp "github.com/last9/mcp-go-sdk/mcp"
1314
"github.com/modelcontextprotocol/go-sdk/mcp"
1415
)
1516

1617
func main() {
1718
log.Printf("Starting Last9 MCP Server v%s", utils.Version)
1819

20+
// Load .env file if it exists (ignore errors if file doesn't exist)
21+
if err := godotenv.Load(); err != nil {
22+
log.Printf("No .env file found or error loading it (this is ok): %v", err)
23+
}
24+
1925
cfg, err := utils.SetupConfig(models.Config{})
2026
if err != nil {
2127
log.Fatalf("config error: %v", err)

0 commit comments

Comments
 (0)