Skip to content

The only tool you need to know what is happening and how to fix it.

feat: pprof minor ui/dx improvements (#241)

narrow-adventure16fc6765813c
diff --git a/backend/app/cache/project_cache.go b/backend/app/cache/project_cache.go
index f71d4819..d4d5f6ff 100644
--- a/backend/app/cache/project_cache.go
+++ b/backend/app/cache/project_cache.go
@@ -60,16 +60,26 @@ func (c *projectCache) Refresh(ctx context.Context) error {
return nil
}
+func copyProject(proj *models.Project) *models.Project {
+ if proj == nil {
+ return nil
+ }
+ cp := *proj
+ cp.HealthcheckPaths = append(models.StringSlice(nil), proj.HealthcheckPaths...)
+ cp.ProfileLabelAllowlist = append(models.StringSlice(nil), proj.ProfileLabelAllowlist...)
+ return &cp
+}
+
func (c *projectCache) GetByToken(token string) *models.Project {
c.mu.RLock()
defer c.mu.RUnlock()
- return c.projects[token]
+ return copyProject(c.projects[token])
}
func (c *projectCache) GetById(id uuid.UUID) *models.Project {
c.mu.RLock()
defer c.mu.RUnlock()
- return c.projectsById[id]
+ return copyProject(c.projectsById[id])
}
func (c *projectCache) GetAll() []*models.Project {
@@ -78,7 +88,7 @@ func (c *projectCache) GetAll() []*models.Project {
result := make([]*models.Project, 0, len(c.projectsById))
for _, proj := range c.projectsById {
- result = append(result, proj)
+ result = append(result, copyProject(proj))
}
sort.Slice(result, func(i, j int) bool {
@@ -109,6 +119,7 @@ func (c *projectCache) UpdateProject(proj *models.Project) {
cached.Framework = proj.Framework
cached.DropHealthyHealthchecks = proj.DropHealthyHealthchecks
cached.HealthcheckPaths = proj.HealthcheckPaths
+ cached.ProfileLabelAllowlist = proj.ProfileLabelAllowlist
}
func (c *projectCache) RemoveProject(id uuid.UUID) {
@@ -128,7 +139,7 @@ func (c *projectCache) RemoveProject(id uuid.UUID) {
func (c *projectCache) GetBySourceMapToken(token string) *models.Project {
c.mu.RLock()
defer c.mu.RUnlock()
- return c.projectsBySourceMapToken[token]
+ return copyProject(c.projectsBySourceMapToken[token])
}
func (c *projectCache) UpdateSourceMapToken(projectId uuid.UUID, token string) {
diff --git a/backend/app/cache/project_cache_test.go b/backend/app/cache/project_cache_test.go
new file mode 100644
index 00000000..0e03bddf
--- /dev/null
+++ b/backend/app/cache/project_cache_test.go
@@ -0,0 +1,62 @@
+package cache
+
+import (
+ "fmt"
+ "sync"
+ "testing"
+ "time"
+
+ "github.com/google/uuid"
+ "github.com/tracewayapp/traceway/backend/app/models"
+)
+
+func TestProjectCache_ConcurrentAllowlistReadWrite(t *testing.T) {
+ id := uuid.New()
+ ProjectCache.AddProject(&models.Project{
+ Id: id,
+ Token: "tok-" + id.String(),
+ ProfileLabelAllowlist: models.StringSlice{"tenant"},
+ HealthcheckPaths: models.StringSlice{"/health"},
+ })
+ t.Cleanup(func() { ProjectCache.RemoveProject(id) })
+
+ stop := time.Now().Add(200 * time.Millisecond)
+ var wg sync.WaitGroup
+
+ wg.Add(1)
+ go func() {
+ defer wg.Done()
+ i := 0
+ for time.Now().Before(stop) {
+ i++
+ ProjectCache.UpdateProject(&models.Project{
+ Id: id,
+ ProfileLabelAllowlist: models.StringSlice{"tenant", "region", fmt.Sprintf("k%d", i)},
+ HealthcheckPaths: models.StringSlice{"/health", fmt.Sprintf("/h%d", i)},
+ })
+ }
+ }()
+
+ for range 4 {
+ wg.Add(1)
+ go func() {
+ defer wg.Done()
+ for time.Now().Before(stop) {
+ p := ProjectCache.GetById(id)
+ if p == nil {
+ continue
+ }
+ sink := 0
+ for range p.ProfileLabelAllowlist {
+ sink++
+ }
+ for range p.HealthcheckPaths {
+ sink++
+ }
+ _ = sink
+ }
+ }()
+ }
+
+ wg.Wait()
+}
diff --git a/backend/app/controllers/clientcontrollers/profile_ingest.controller.go b/backend/app/controllers/clientcontrollers/profile_ingest.controller.go
index da6e43a6..cb1ab720 100644
--- a/backend/app/controllers/clientcontrollers/profile_ingest.controller.go
+++ b/backend/app/controllers/clientcontrollers/profile_ingest.controller.go
@@ -56,12 +56,18 @@ func (e profileIngestController) Ingest(c *gin.Context) {
serviceName = project.Name
}
+ var labelAllowlist []string
+ if project != nil {
+ labelAllowlist = project.ProfileLabelAllowlist
+ }
+
ingestCtx := profiling.IngestContext{
ProjectId: projectId,
DefaultServiceName: serviceName,
ServerName: c.Query("serverName"),
AppVersion: c.Query("appVersion"),
ReceivedAt: time.Now().UTC(),
+ LabelAllowlist: profiling.NewLabelAllowSet(labelAllowlist),
}
decoded, err := (profiling.PprofDecoder{}).Decode(ingestCtx, body)
diff --git a/backend/app/controllers/otelcontrollers/otel.controller.go b/backend/app/controllers/otelcontrollers/otel.controller.go
index ff2cd978..df72a91a 100644
--- a/backend/app/controllers/otelcontrollers/otel.controller.go
+++ b/backend/app/controllers/otelcontrollers/otel.controller.go
@@ -278,16 +278,20 @@ func (o otelController) ExportProfiles(c *gin.Context) {
return
}
- if project, exists := c.Get(middleware.ProjectContextKey); exists {
- if p, ok := project.(*models.Project); ok && p.OrganizationId != nil {
- if attrs := traceway.GetAttributesFromContext(c); attrs != nil {
- attrs.SetTag("organization_id", fmt.Sprintf("%d", *p.OrganizationId))
- }
- if !hooks.CanReport(*p.OrganizationId) {
- monitoring.RecordRateLimited(*p.OrganizationId)
- c.AbortWithStatus(http.StatusTooManyRequests)
- return
- }
+ var project *models.Project
+ if projectAsAny, exists := c.Get(middleware.ProjectContextKey); exists {
+ if p, ok := projectAsAny.(*models.Project); ok {
+ project = p
+ }
+ }
+ if project != nil && project.OrganizationId != nil {
+ if attrs := traceway.GetAttributesFromContext(c); attrs != nil {
+ attrs.SetTag("organization_id", fmt.Sprintf("%d", *project.OrganizationId))
+ }
+ if !hooks.CanReport(*project.OrganizationId) {
+ monitoring.RecordRateLimited(*project.OrganizationId)
+ c.AbortWithStatus(http.StatusTooManyRequests)
+ return
}
}
@@ -297,10 +301,16 @@ func (o otelController) ExportProfiles(c *gin.Context) {
return
}
+ var labelAllowlist []string
+ if project != nil {
+ labelAllowlist = project.ProfileLabelAllowlist
+ }
+
convertStart := time.Now()
decoded, err := profiling.OTLPDecoder{}.Decode(profiling.IngestContext{
- ProjectId: projectId,
- ReceivedAt: time.Now().UTC(),
+ ProjectId: projectId,
+ ReceivedAt: time.Now().UTC(),
+ LabelAllowlist: profiling.NewLabelAllowSet(labelAllowlist),
}, payload)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
diff --git a/backend/app/controllers/profile.controller.go b/backend/app/controllers/profile.controller.go
index 58f3940b..fa1c8229 100644
--- a/backend/app/controllers/profile.controller.go
+++ b/backend/app/controllers/profile.controller.go
@@ -2,11 +2,15 @@ package controllers
import (
"net/http"
+ "slices"
"time"
+ "unicode/utf8"
"github.com/gin-gonic/gin"
+ "github.com/tracewayapp/traceway/backend/app/cache"
"github.com/tracewayapp/traceway/backend/app/middleware"
"github.com/tracewayapp/traceway/backend/app/models"
+ "github.com/tracewayapp/traceway/backend/app/profiling"
"github.com/tracewayapp/traceway/backend/app/repositories"
"github.com/tracewayapp/traceway/backend/app/services"
traceway "go.tracewayapp.com"
@@ -127,6 +131,20 @@ func (p profileController) GetFlameGraph(c *gin.Context) {
return
}
+ if len(request.Labels) > 0 {
+ var additional []string
+ if proj := cache.ProjectCache.GetById(projectId); proj != nil {
+ additional = proj.ProfileLabelAllowlist
+ }
+ allowed := profiling.LabelAllowKeys(additional)
+ for key := range request.Labels {
+ if utf8.RuneCountInString(key) > 100 || !slices.Contains(allowed, key) {
+ c.JSON(http.StatusBadRequest, gin.H{"error": "label filter key is not in the project's profile label allowlist"})
+ return
+ }
+ }
+ }
+
rows, err := repositories.ProfileRepository.GetFlameGraph(c, projectId, request.ServiceName, request.Type, request.FromDate, request.ToDate, request.Labels)
if err != nil {
c.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("error loading flame graph: %w", err))
@@ -153,7 +171,12 @@ func (p profileController) DiscoverLabels(c *gin.Context) {
return
}
- labels, err := repositories.ProfileRepository.DiscoverLabels(c, projectId, request.ServiceName, request.Type, request.FromDate, request.ToDate)
+ var additional []string
+ if proj := cache.ProjectCache.GetById(projectId); proj != nil {
+ additional = proj.ProfileLabelAllowlist
+ }
+
+ labels, err := repositories.ProfileRepository.DiscoverLabels(c, projectId, request.ServiceName, request.Type, request.FromDate, request.ToDate, profiling.LabelAllowKeys(additional))
if err != nil {
c.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("error discovering profile labels: %w", err))
return
diff --git a/backend/app/controllers/project.controller.go b/backend/app/controllers/project.controller.go
index c4c8ddef..b72e555c 100644
--- a/backend/app/controllers/project.controller.go
+++ b/backend/app/controllers/project.controller.go
@@ -5,6 +5,7 @@ import (
"github.com/tracewayapp/traceway/backend/app/middleware"
"github.com/tracewayapp/traceway/backend/app/models"
"github.com/tracewayapp/traceway/backend/app/db"
+ "github.com/tracewayapp/traceway/backend/app/profiling"
"github.com/tracewayapp/traceway/backend/app/repositories"
"database/sql"
"fmt"
@@ -53,6 +54,35 @@ var validFrameworks = map[string]bool{
// Project name validation regex: allows alphanumeric, spaces, hyphens, and underscores
var projectNameRegex = regexp.MustCompile(`^[a-zA-Z0-9\s\-_]+$`)
+// Profile label key validation regex: letters, numbers, and . _ : -
+var profileLabelKeyRegex = regexp.MustCompile(`^[a-zA-Z0-9._:-]+$`)
+
+func cleanProfileLabelAllowlist(in []string) ([]string, string) {
+ if len(in) > 20 {
+ return nil, "At most 20 profile label keys are allowed"
+ }
+ cleaned := make([]string, 0, len(in))
+ seen := make(map[string]struct{})
+ for _, key := range in {
+ key = strings.TrimSpace(key)
+ if key == "" || strings.EqualFold(key, profiling.LabelEndpoint) {
+ continue
+ }
+ if utf8.RuneCountInString(key) > 100 {
+ return nil, "Profile label keys must be at most 100 characters"
+ }
+ if !profileLabelKeyRegex.MatchString(key) {
+ return nil, "Profile label keys may only contain letters, numbers, and . _ : -"
+ }
+ if _, dup := seen[key]; dup {
+ continue
+ }
+ seen[key] = struct{}{}
+ cleaned = append(cleaned, key)
+ }
+ return cleaned, ""
+}
+
type projectController struct{}
type CreateProjectRequest struct {
@@ -65,6 +95,7 @@ type UpdateProjectRequest struct {
Framework string `json:"framework" binding:"required"`
DropHealthyHealthchecks *bool `json:"dropHealthyHealthchecks"`
HealthcheckPaths *[]string `json:"healthcheckPaths"`
+ ProfileLabelAllowlist *[]string `json:"profileLabelAllowlist"`
}
type DeleteProjectRequest struct {
@@ -191,6 +222,16 @@ func (p projectController) UpdateProject(c *gin.Context) {
healthcheckPaths = &cleaned
}
+ var profileLabelAllowlist *[]string
+ if request.ProfileLabelAllowlist != nil {
+ cleaned, errMsg := cleanProfileLabelAllowlist(*request.ProfileLabelAllowlist)
+ if errMsg != "" {
+ c.JSON(http.StatusUnprocessableEntity, gin.H{"error": errMsg})
+ return
+ }
+ profileLabelAllowlist = &cleaned
+ }
+
projectId, err := middleware.GetProjectId(c)
if err != nil {
c.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("RequireProjectAccess middleware must be applied: %w", err))
@@ -198,7 +239,7 @@ func (p projectController) UpdateProject(c *gin.Context) {
}
project, err := db.ExecuteTransaction(func(tx *sql.Tx) (*models.Project, error) {
- return repositories.ProjectRepository.Update(tx, projectId, request.Name, request.Framework, request.DropHealthyHealthchecks, healthcheckPaths)
+ return repositories.ProjectRepository.Update(tx, projectId, request.Name, request.Framework, request.DropHealthyHealthchecks, healthcheckPaths, profileLabelAllowlist)
})
if err != nil {
c.AbortWithError(http.StatusInternalServerError, traceway.NewStackTraceErrorf("error updating project: %w", err))
diff --git a/backend/app/controllers/project_controller_test.go b/backend/app/controllers/project_controller_test.go
new file mode 100644
index 00000000..533b62d8
--- /dev/null
+++ b/backend/app/controllers/project_controller_test.go
@@ -0,0 +1,53 @@
+package controllers
+
+import (
+ "fmt"
+ "slices"
+ "strings"
+ "testing"
+)
+
+func twentyOneLabelKeys() []string {
+ keys := make([]string, 21)
+ for i := range keys {
+ keys[i] = fmt.Sprintf("k%d", i)
+ }
+ return keys
+}
+
+func TestCleanProfileLabelAllowlist(t *testing.T) {
+ tests := []struct {
+ name string
+ in []string
+ want []string
+ wantErr bool
+ }{
+ {name: "valid keys incl dotted/colon/hyphen", in: []string{"tenant", "http.route", "region-1", "team:core"}, want: []string{"tenant", "http.route", "region-1", "team:core"}},
+ {name: "drops endpoint case-insensitively", in: []string{"endpoint", "Endpoint", "ENDPOINT", "tenant"}, want: []string{"tenant"}},
+ {name: "dedups preserving order", in: []string{"tenant", "tenant", "region"}, want: []string{"tenant", "region"}},
+ {name: "skips empty and whitespace", in: []string{"", " ", "tenant"}, want: []string{"tenant"}},
+ {name: "all-endpoint yields empty", in: []string{"endpoint", " "}, want: []string{}},
+ {name: "rejects spaces", in: []string{"has space"}, wantErr: true},
+ {name: "rejects slash", in: []string{"a/b"}, wantErr: true},
+ {name: "rejects at-sign", in: []string{"user@host"}, wantErr: true},
+ {name: "rejects more than 20 keys", in: twentyOneLabelKeys(), wantErr: true},
+ {name: "rejects over-long key", in: []string{strings.Repeat("a", 101)}, wantErr: true},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ got, errMsg := cleanProfileLabelAllowlist(tt.in)
+ if tt.wantErr {
+ if errMsg == "" {
+ t.Fatalf("expected validation error, got cleaned=%v", got)
+ }
+ return
+ }
+ if errMsg != "" {
+ t.Fatalf("unexpected error: %s", errMsg)
+ }
+ if !slices.Equal(got, tt.want) {
+ t.Errorf("cleaned = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
diff --git a/backend/app/migrations/pg/0041_add_profile_label_allowlist_to_projects.up.sql b/backend/app/migrations/pg/0041_add_profile_label_allowlist_to_projects.up.sql
new file mode 100644
index 00000000..5b53669a
--- /dev/null
+++ b/backend/app/migrations/pg/0041_add_profile_label_allowlist_to_projects.up.sql
@@ -0,0 +1 @@
+ALTER TABLE projects ADD COLUMN profile_label_allowlist TEXT NOT NULL DEFAULT '[]'
diff --git a/backend/app/migrations/sqlite/0015_add_profile_label_allowlist_to_projects.up.sql b/backend/app/migrations/sqlite/0015_add_profile_label_allowlist_to_projects.up.sql
new file mode 100644
index 00000000..5b53669a
--- /dev/null
+++ b/backend/app/migrations/sqlite/0015_add_profile_label_allowlist_to_projects.up.sql
@@ -0,0 +1 @@
+ALTER TABLE projects ADD COLUMN profile_label_allowlist TEXT NOT NULL DEFAULT '[]'
diff --git a/backend/app/models/project.model.go b/backend/app/models/project.model.go
index 4bbefbd4..6d63a29b 100644
--- a/backend/app/models/project.model.go
+++ b/backend/app/models/project.model.go
@@ -53,6 +53,7 @@ type Project struct {
SourceMapToken *string `json:"sourceMapToken,omitempty"`
DropHealthyHealthchecks bool `json:"dropHealthyHealthchecks"`
HealthcheckPaths StringSlice `json:"healthcheckPaths"`
+ ProfileLabelAllowlist StringSlice `json:"profileLabelAllowlist"`
}
func (p Project) ToProjectWithBackendUrl() *ProjectWithBackendUrl {
diff --git a/backend/app/profiling/decoder.go b/backend/app/profiling/decoder.go
index 44c075fa..c48625dc 100644
--- a/backend/app/profiling/decoder.go
+++ b/backend/app/profiling/decoder.go
@@ -12,6 +12,7 @@ type IngestContext struct {
ServerName string
AppVersion string
ReceivedAt time.Time
+ LabelAllowlist map[string]struct{}
}
type Decoder interface {
diff --git a/backend/app/profiling/model.go b/backend/app/profiling/model.go
index 68934f15..b53ca6b6 100644
--- a/backend/app/profiling/model.go
+++ b/backend/app/profiling/model.go
@@ -3,6 +3,7 @@ package profiling
import (
"hash/fnv"
"sort"
+ "strings"
"time"
)
@@ -20,8 +21,27 @@ var keptSampleTypes = map[string]string{
const LabelEndpoint = "endpoint"
-var allowedLabels = map[string]struct{}{
- LabelEndpoint: {},
+const MaxLabelValuesPerKey = 1000
+
+func NewLabelAllowSet(additional []string) map[string]struct{} {
+ allow := map[string]struct{}{LabelEndpoint: {}}
+ for _, k := range additional {
+ k = strings.TrimSpace(k)
+ if k != "" {
+ allow[k] = struct{}{}
+ }
+ }
+ return allow
+}
+
+func LabelAllowKeys(additional []string) []string {
+ allow := NewLabelAllowSet(additional)
+ keys := make([]string, 0, len(allow))
+ for k := range allow {
+ keys = append(keys, k)
+ }
+ sort.Strings(keys)
+ return keys
}
func IsGauge(profileType string) bool {
@@ -66,10 +86,10 @@ func HashFrames(frames []string) uint64 {
return h.Sum64()
}
-func allowlistedLabels(raw map[string][]string) map[string]string {
+func allowlistedLabels(raw map[string][]string, allow map[string]struct{}) map[string]string {
var out map[string]string
for k, v := range raw {
- if _, ok := allowedLabels[k]; !ok {
+ if _, ok := allow[k]; !ok {
continue
}
if len(v) == 0 {
diff --git a/backend/app/profiling/otlp_decoder.go b/backend/app/profiling/otlp_decoder.go
index f73908dc..bf361a7d 100644
--- a/backend/app/profiling/otlp_decoder.go
+++ b/backend/app/profiling/otlp_decoder.go
@@ -59,7 +59,7 @@ func decodeProfile(ctx IngestContext, serviceName string, resolver *stackResolve
end = start.Add(time.Duration(dur))
}
- values := make(map[uint64]int64)
+ values := make(map[dedupKey]*dedupValue)
stacks := make(map[uint64][]string)
for _, s := range p.Samples {
rs := resolver.lookup(s.StackIndex)
@@ -77,7 +77,14 @@ func decodeProfile(ctx IngestContext, serviceName string, resolver *stackResolve
if v == 0 {
continue
}
- values[rs.hash] += v
+ labels := resolver.attributes(s.AttributeIndices, ctx.LabelAllowlist)
+ key := dedupKey{typ: internalType, stackHash: rs.hash, labelHash: labelFingerprint(labels)}
+ agg := values[key]
+ if agg == nil {
+ agg = &dedupValue{labels: labels}
+ values[key] = agg
+ }
+ agg.value += v
stacks[rs.hash] = rs.frames
}
@@ -93,8 +100,8 @@ func decodeProfile(ctx IngestContext, serviceName string, resolver *stackResolve
for hash, frames := range stacks {
decoded.Stacks = append(decoded.Stacks, Stack{Hash: hash, Frames: frames})
}
- for hash, v := range values {
- decoded.Samples = append(decoded.Samples, Sample{Type: internalType, StackHash: hash, Value: v})
+ for key, agg := range values {
+ decoded.Samples = append(decoded.Samples, Sample{Type: key.typ, StackHash: key.stackHash, Value: agg.value, Labels: agg.labels})
}
return decoded, true
}
@@ -124,6 +131,38 @@ func newStackResolver(dict *profilespb.ProfilesDictionary) *stackResolver {
return &stackResolver{dict: dict, cache: make(map[int32]resolvedStack)}
}
+func (r *stackResolver) attributes(indices []int32, allow map[string]struct{}) map[string]string {
+ if len(indices) == 0 || len(allow) == 0 {
+ return nil
+ }
+ var out map[string]string
+ for _, idx := range indices {
+ if idx < 0 || int(idx) >= len(r.dict.AttributeTable) {
+ continue
+ }
+ kv := r.dict.AttributeTable[idx]
+ if kv == nil || kv.Value == nil {
+ continue
+ }
+ key := r.stringAt(kv.KeyStrindex)
+ if key == "" {
+ continue
+ }
+ if _, ok := allow[key]; !ok {
+ continue
+ }
+ sv, ok := kv.Value.Value.(*commonpb.AnyValue_StringValue)
+ if !ok {
+ continue
+ }
+ if out == nil {
+ out = make(map[string]string)
+ }
+ out[key] = sv.StringValue
+ }
+ return out
+}
+
func (r *stackResolver) stringAt(i int32) string {
if i < 0 || int(i) >= len(r.dict.StringTable) {
return ""
diff --git a/backend/app/profiling/otlp_decoder_test.go b/backend/app/profiling/otlp_decoder_test.go
index 43560753..6f6a4540 100644
--- a/backend/app/profiling/otlp_decoder_test.go
+++ b/backend/app/profiling/otlp_decoder_test.go
@@ -19,6 +19,7 @@ type otlpBuilder struct {
functions []*profilespb.Function
locations []*profilespb.Location
stacks []*profilespb.Stack
+ attributes []*profilespb.KeyValueAndUnit
profiles []*profilespb.Profile
}
@@ -80,6 +81,15 @@ func (b *otlpBuilder) inlinedStack(rootFirst ...string) int32 {
return idx
}
+func (b *otlpBuilder) attr(key, value string) int32 {
+ idx := int32(len(b.attributes))
+ b.attributes = append(b.attributes, &profilespb.KeyValueAndUnit{
+ KeyStrindex: b.str(key),
+ Value: &commonpb.AnyValue{Value: &commonpb.AnyValue_StringValue{StringValue: value}},
+ })
+ return idx
+}
+
func (b *otlpBuilder) profile(typeName, unit string, timeNanos, durNanos uint64, samples ...*profilespb.Sample) {
b.profiles = append(b.profiles, &profilespb.Profile{
SampleType: &profilespb.ValueType{TypeStrindex: b.str(typeName), UnitStrindex: b.str(unit)},
@@ -100,10 +110,11 @@ func (b *otlpBuilder) build(t *testing.T) []byte {
}
req := &colprofilespb.ExportProfilesServiceRequest{
Dictionary: &profilespb.ProfilesDictionary{
- StringTable: b.strings,
- FunctionTable: b.functions,
- LocationTable: b.locations,
- StackTable: b.stacks,
+ StringTable: b.strings,
+ FunctionTable: b.functions,
+ LocationTable: b.locations,
+ StackTable: b.stacks,
+ AttributeTable: b.attributes,
},
ResourceProfiles: []*profilespb.ResourceProfiles{{
Resource: res,
@@ -123,6 +134,10 @@ func otlpSample(stackIdx int32, value int64) *profilespb.Sample {
return &profilespb.Sample{StackIndex: stackIdx, Values: []int64{value}}
}
+func otlpSampleAttr(stackIdx int32, value int64, attrIdxs ...int32) *profilespb.Sample {
+ return &profilespb.Sample{StackIndex: stackIdx, Values: []int64{value}, AttributeIndices: attrIdxs}
+}
+
func decodeOTLPAll(t *testing.T, payload []byte) []Decoded {
t.Helper()
out, err := OTLPDecoder{}.Decode(testIngest, payload)
@@ -395,6 +410,95 @@ func TestDecoderParity_PprofVsOTLP(t *testing.T) {
}
}
+func TestOTLPDecoder_ExtractsAllowlistedLabels(t *testing.T) {
+ b := newOTLPBuilder()
+ b.serviceName = "checkout"
+ s := b.frameStack("main.main", "main.work")
+ epCheckout := b.attr("endpoint", "/checkout")
+ epCart := b.attr("endpoint", "/cart")
+ tenant := b.attr("tenant", "acme")
+ reqID := b.attr("request_id", "abc-123")
+ b.profile("cpu", "nanoseconds", 1_700_000_000_000_000_000, 1_000_000_000,
+ otlpSampleAttr(s, 300, epCheckout, tenant, reqID),
+ otlpSampleAttr(s, 100, epCart),
+ otlpSampleAttr(s, 50, epCheckout, tenant, reqID),
+ )
+
+ out, err := OTLPDecoder{}.Decode(IngestContext{
+ DefaultServiceName: "checkout",
+ ReceivedAt: testIngest.ReceivedAt,
+ LabelAllowlist: NewLabelAllowSet([]string{"tenant"}),
+ }, b.build(t))
+ if err != nil {
+ t.Fatalf("Decode: %v", err)
+ }
+
+ var samples []Sample
+ for _, d := range out {
+ samples = append(samples, d.Samples...)
+ }
+ if len(samples) != 2 {
+ t.Fatalf("expected 2 label-separated samples, got %d", len(samples))
+ }
+ byEndpoint := map[string]Sample{}
+ for _, smp := range samples {
+ byEndpoint[smp.Labels[LabelEndpoint]] = smp
+ }
+ checkout := byEndpoint["/checkout"]
+ if checkout.Value != 350 {
+ t.Errorf("/checkout value = %d, want 350 (same stack+labels summed)", checkout.Value)
+ }
+ if checkout.Labels["tenant"] != "acme" {
+ t.Errorf("tenant label = %q, want acme (additional allowlisted key kept)", checkout.Labels["tenant"])
+ }
+ if _, ok := checkout.Labels["request_id"]; ok {
+ t.Errorf("non-allowlisted request_id must be dropped, got %v", checkout.Labels)
+ }
+ if byEndpoint["/cart"].Value != 100 {
+ t.Errorf("/cart value = %d, want 100", byEndpoint["/cart"].Value)
+ }
+ if got := len(flattenStacks(out)); got != 1 {
+ t.Errorf("unique stacks = %d, want 1 (label-separated samples still share the stack row)", got)
+ }
+}
+
+func TestOTLPDecoder_DropsNonStringAttributes(t *testing.T) {
+ b := newOTLPBuilder()
+ b.serviceName = "checkout"
+ s := b.frameStack("main.main", "main.work")
+ ep := b.attr("endpoint", "/checkout")
+ numIdx := int32(len(b.attributes))
+ b.attributes = append(b.attributes, &profilespb.KeyValueAndUnit{
+ KeyStrindex: b.str("request_count"),
+ Value: &commonpb.AnyValue{Value: &commonpb.AnyValue_IntValue{IntValue: 42}},
+ })
+ b.profile("cpu", "nanoseconds", 1_700_000_000_000_000_000, 1_000_000_000,
+ otlpSampleAttr(s, 100, ep, numIdx),
+ )
+
+ out, err := OTLPDecoder{}.Decode(IngestContext{
+ DefaultServiceName: "checkout",
+ ReceivedAt: testIngest.ReceivedAt,
+ LabelAllowlist: NewLabelAllowSet([]string{"request_count"}),
+ }, b.build(t))
+ if err != nil {
+ t.Fatalf("Decode: %v", err)
+ }
+
+ var labels map[string]string
+ for _, d := range out {
+ for _, smp := range d.Samples {
+ labels = smp.Labels
+ }
+ }
+ if labels[LabelEndpoint] != "/checkout" {
+ t.Errorf("labels = %v, want endpoint /checkout", labels)
+ }
+ if _, ok := labels["request_count"]; ok {
+ t.Errorf("non-string IntValue attribute must be dropped even when allowlisted, got %v", labels)
+ }
+}
+
func stacksEqual(a, b map[uint64][]string) bool {
if len(a) != len(b) {
return false
diff --git a/backend/app/profiling/pprof_decoder.go b/backend/app/profiling/pprof_decoder.go
index c60c235a..1a3afc3c 100644
--- a/backend/app/profiling/pprof_decoder.go
+++ b/backend/app/profiling/pprof_decoder.go
@@ -63,7 +63,7 @@ func (PprofDecoder) Decode(ctx IngestContext, payload []byte) ([]Decoded, error)
continue
}
hash := HashFrames(frames)
- sampleLabels := allowlistedLabels(s.Label)
+ sampleLabels := allowlistedLabels(s.Label, ctx.LabelAllowlist)
labelHash := labelFingerprint(sampleLabels)
for _, k := range kept {
if k.index >= len(s.Value) || s.Value[k.index] == 0 {
diff --git a/backend/app/profiling/pprof_decoder_test.go b/backend/app/profiling/pprof_decoder_test.go
index 59140ebf..1fb84f32 100644
--- a/backend/app/profiling/pprof_decoder_test.go
+++ b/backend/app/profiling/pprof_decoder_test.go
@@ -15,6 +15,7 @@ var testIngest = IngestContext{
ServerName: "pod-abc",
AppVersion: "1.2.3",
ReceivedAt: time.Unix(1_700_000_000, 0).UTC(),
+ LabelAllowlist: NewLabelAllowSet(nil),
}
func fn(id uint64, name, file string) *profile.Function {
diff --git a/backend/app/profiling/pprof_labels_test.go b/backend/app/profiling/pprof_labels_test.go
index 967ba19f..a11931a5 100644
--- a/backend/app/profiling/pprof_labels_test.go
+++ b/backend/app/profiling/pprof_labels_test.go
@@ -36,6 +36,35 @@ func TestPprofDecoder_KeepsOnlyAllowlistedLabels(t *testing.T) {
}
}
+func TestPprofDecoder_HonorsAdditionalAllowlistedKeys(t *testing.T) {
+ main := fn(1, "main.main", "main.go")
+ lMain := loc(1, profile.Line{Function: main, Line: 10})
+ samples := []*profile.Sample{{
+ Location: []*profile.Location{lMain},
+ Value: []int64{1, 100},
+ Label: map[string][]string{"endpoint": {"/x"}, "tenant": {"acme"}, "request_id": {"abc"}},
+ }}
+ out, err := PprofDecoder{}.Decode(IngestContext{
+ DefaultServiceName: "checkout",
+ ReceivedAt: testIngest.ReceivedAt,
+ LabelAllowlist: NewLabelAllowSet([]string{"tenant"}),
+ }, labeledCPU(t, samples, []*profile.Function{main}, []*profile.Location{lMain}))
+ if err != nil {
+ t.Fatalf("Decode: %v", err)
+ }
+ cpu := sampleByType(out[0], TypeCPUNanos)
+ if len(cpu) != 1 {
+ t.Fatalf("expected 1 sample, got %d", len(cpu))
+ }
+ got := cpu[0].Labels
+ if got[LabelEndpoint] != "/x" || got["tenant"] != "acme" {
+ t.Errorf("labels = %v, want {endpoint:/x, tenant:acme} (built-in + additional allowlisted)", got)
+ }
+ if _, ok := got["request_id"]; ok {
+ t.Errorf("non-allowlisted request_id must be dropped, got %v", got)
+ }
+}
+
func TestPprofDecoder_LabelsSeparateTheDedup(t *testing.T) {
main := fn(1, "main.main", "main.go")
work := fn(2, "main.work", "work.go")
@@ -100,3 +129,33 @@ func TestBuildRows_CarriesSampleLabels(t *testing.T) {
t.Errorf("ProfileSample.Labels = %v, want {endpoint:/x}", samples[0].Labels)
}
}
+
+func TestPprofDecoder_DropsNumericLabels(t *testing.T) {
+ main := fn(1, "main.main", "main.go")
+ lMain := loc(1, profile.Line{Function: main, Line: 10})
+ samples := []*profile.Sample{{
+ Location: []*profile.Location{lMain},
+ Value: []int64{1, 100},
+ Label: map[string][]string{"endpoint": {"/x"}},
+ NumLabel: map[string][]int64{"request_count": {42}},
+ }}
+ out, err := PprofDecoder{}.Decode(IngestContext{
+ DefaultServiceName: "checkout",
+ ReceivedAt: testIngest.ReceivedAt,
+ LabelAllowlist: NewLabelAllowSet([]string{"request_count"}),
+ }, labeledCPU(t, samples, []*profile.Function{main}, []*profile.Location{lMain}))
+ if err != nil {
+ t.Fatalf("Decode: %v", err)
+ }
+ cpu := sampleByType(out[0], TypeCPUNanos)
+ if len(cpu) != 1 {
+ t.Fatalf("expected 1 sample, got %d", len(cpu))
+ }
+ got := cpu[0].Labels
+ if got[LabelEndpoint] != "/x" {
+ t.Errorf("labels = %v, want endpoint /x", got)
+ }
+ if _, ok := got["request_count"]; ok {
+ t.Errorf("numeric NumLabel must be dropped even when allowlisted, got %v", got)
+ }
+}
diff --git a/backend/app/repositories/attribute_filter_dotted_key_test.go b/backend/app/repositories/attribute_filter_dotted_key_test.go
new file mode 100644
index 00000000..7d53e4b7
--- /dev/null
+++ b/backend/app/repositories/attribute_filter_dotted_key_test.go
@@ -0,0 +1,86 @@
+//go:build !pgch
+
+package repositories
+
+import (
+ "context"
+ "testing"
+ "time"
+
+ "github.com/google/uuid"
+ "github.com/tracewayapp/traceway/backend/app/models"
+)
+
+func TestLogRecordRepository_Search_FiltersByDottedAttributeKey(t *testing.T) {
+ setupTestDB(t)
+ ctx := context.Background()
+ projectId := uuid.New()
+ base := time.Date(2026, 1, 1, 12, 0, 0, 0, time.UTC)
+
+ record := func(route string) models.LogRecord {
+ return models.LogRecord{
+ Id: uuid.New(),
+ ProjectId: projectId,
+ Timestamp: base,
+ ServiceName: "checkout",
+ Body: "request handled",
+ LogAttributes: map[string]string{"http.route": route},
+ }
+ }
+ if err := LogRecordRepository.InsertAsync(ctx, []models.LogRecord{
+ record("GET /checkout"),
+ record("GET /cart"),
+ }); err != nil {
+ t.Fatalf("InsertAsync: %v", err)
+ }
+
+ records, total, err := LogRecordRepository.Search(ctx, LogSearchParams{
+ ProjectId: projectId,
+ FromDate: base.Add(-time.Hour),
+ ToDate: base.Add(time.Hour),
+ AttributeFilters: []LogAttributeFilter{{Scope: "log", Key: "http.route", Value: "GET /checkout"}},
+ })
+ if err != nil {
+ t.Fatalf("Search (dotted attribute filter): %v", err)
+ }
+ if total != 1 || len(records) != 1 {
+ t.Fatalf("dotted log attribute filter returned %d rows (total=%d), want 1 (dotted key must match in SQLite mode)", len(records), total)
+ }
+ if got := records[0].LogAttributes["http.route"]; got != "GET /checkout" {
+ t.Errorf("matched record http.route = %q, want GET /checkout", got)
+ }
+}
+
+func TestSessionRepository_FindAll_FiltersByDottedAttributeKey(t *testing.T) {
+ setupTestDB(t)
+ ctx := context.Background()
+ projectId := uuid.New()
+ base := time.Date(2026, 1, 1, 12, 0, 0, 0, time.UTC)
+
+ session := func(route string) models.Session {
+ return models.Session{
+ Id: uuid.New(),
+ ProjectId: projectId,
+ StartedAt: base,
+ Attributes: map[string]string{"http.route": route},
+ }
+ }
+ if err := SessionRepository.Upsert(ctx, []models.Session{
+ session("GET /checkout"),
+ session("GET /cart"),
+ }); err != nil {
+ t.Fatalf("Upsert: %v", err)
+ }
+
+ sessions, total, err := SessionRepository.FindAll(ctx, projectId, base.Add(-time.Hour), base.Add(time.Hour), 1, 50, "started_at", "desc", "",
+ []SessionAttributeFilter{{Key: "http.route", Value: "GET /checkout"}})
+ if err != nil {
+ t.Fatalf("FindAll (dotted attribute filter): %v", err)
+ }
+ if total != 1 || len(sessions) != 1 {
+ t.Fatalf("dotted session attribute filter returned %d rows (total=%d), want 1 (dotted key must match in SQLite mode)", len(sessions), total)
+ }
+ if got := sessions[0].Attributes["http.route"]; got != "GET /checkout" {
+ t.Errorf("matched session http.route = %q, want GET /checkout", got)
+ }
+}
diff --git a/backend/app/repositories/log_record.repository_sqlite.go b/backend/app/repositories/log_record.repository_sqlite.go
index 615a73e7..63d4feec 100644
--- a/backend/app/repositories/log_record.repository_sqlite.go
+++ b/backend/app/repositories/log_record.repository_sqlite.go
@@ -253,7 +253,7 @@ func (r *logRecordRepository) buildWhere(params LogSearchParams) (string, lit.P)
keyPH := fmt.Sprintf("attr_k%d", i)
valPH := fmt.Sprintf("attr_v%d", i)
clauses = append(clauses,
- fmt.Sprintf("json_extract(%s, '$.' || :%s) = :%s", col, keyPH, valPH))
+ fmt.Sprintf("json_extract(%s, '$.\"' || :%s || '\"') = :%s", col, keyPH, valPH))
args[keyPH] = f.Key
args[valPH] = f.Value
}
diff --git a/backend/app/repositories/metric_point.repository_sqlite.go b/backend/app/repositories/metric_point.repository_sqlite.go
index 9ca76494..92b5ab6f 100644
--- a/backend/app/repositories/metric_point.repository_sqlite.go
+++ b/backend/app/repositories/metric_point.repository_sqlite.go
@@ -73,7 +73,7 @@ func (r *metricPointRepository) QueryTimeSeries(ctx context.Context, projectId u
selectClause := fmt.Sprintf("SELECT datetime((strftime('%%s', recorded_at) / %d) * %d, 'unixepoch') AS bucket", secs, secs)
if hasGroupBy {
- selectClause += ", json_extract(tags, '$.' || :group_by) AS group_key"
+ selectClause += ", json_extract(tags, '$.\"' || :group_by || '\"') AS group_key"
}
selectClause += ", " + aggFunc + " AS agg_value FROM metric_points WHERE project_id = :project_id AND name = :name AND recorded_at >= :from AND recorded_at <= :to"
@@ -91,7 +91,7 @@ func (r *metricPointRepository) QueryTimeSeries(ctx context.Context, projectId u
for i, k := range sortedKeys(tagFilters) {
fk := fmt.Sprintf("fk_%d", i)
fv := fmt.Sprintf("fv_%d", i)
- filterClauses += fmt.Sprintf(" AND json_extract(tags, '$.' || :%s) = :%s", fk, fv)
+ filterClauses += fmt.Sprintf(" AND json_extract(tags, '$.\"' || :%s || '\"') = :%s", fk, fv)
params[fk] = k
params[fv] = tagFilters[k]
}
@@ -201,11 +201,11 @@ func (r *metricPointRepository) DiscoverTagValues(ctx context.Context, projectId
lit.RegisterModel[tagValueRow](db.Driver)
results, err := lit.SelectNamed[tagValueRow](db.TelemetryDB,
- `SELECT DISTINCT json_extract(tags, '$.' || :tag_key) AS tag_value
+ `SELECT DISTINCT json_extract(tags, '$."' || :tag_key || '"') AS tag_value
FROM metric_points
WHERE project_id = :project_id AND name = :name AND recorded_at >= :from AND recorded_at <= :to
- AND json_extract(tags, '$.' || :tag_key) IS NOT NULL
- AND json_extract(tags, '$.' || :tag_key) != ''
+ AND json_extract(tags, '$."' || :tag_key || '"') IS NOT NULL
+ AND json_extract(tags, '$."' || :tag_key || '"') != ''
ORDER BY tag_value ASC`,
lit.P{"project_id": projectId, "name": metricName, "tag_key": tagKey, "from": NewSQLiteTime(from), "to": NewSQLiteTime(to)})
if err != nil {
diff --git a/backend/app/repositories/metric_point_repository_test.go b/backend/app/repositories/metric_point_repository_test.go
index fd3ba17c..3126a0cc 100644
--- a/backend/app/repositories/metric_point_repository_test.go
+++ b/backend/app/repositories/metric_point_repository_test.go
@@ -190,6 +190,30 @@ func TestMetricPointRepository_DiscoverTagValues(t *testing.T) {
}
}
+func TestMetricPointRepository_DiscoverTagValues_DottedKey(t *testing.T) {
+ setupTestDB(t)
+ ctx := context.Background()
+ projectId := uuid.New()
+ base := time.Now().UTC().Truncate(time.Hour)
+
+ points := []models.MetricPoint{
+ makeMetricPoint(projectId, "http.server.duration", 1.0, map[string]string{"http.route": "GET /a"}, base),
+ makeMetricPoint(projectId, "http.server.duration", 2.0, map[string]string{"http.route": "GET /b"}, base.Add(time.Minute)),
+ makeMetricPoint(projectId, "http.server.duration", 3.0, map[string]string{"http.route": "GET /a"}, base.Add(2*time.Minute)),
+ }
+ if err := MetricPointRepository.InsertAsync(ctx, points); err != nil {
+ t.Fatalf("InsertAsync failed: %v", err)
+ }
+
+ values, err := MetricPointRepository.DiscoverTagValues(ctx, projectId, "http.server.duration", "http.route", base.Add(-time.Minute), base.Add(time.Hour))
+ if err != nil {
+ t.Fatalf("DiscoverTagValues failed: %v", err)
+ }
+ if len(values) != 2 || values[0] != "GET /a" || values[1] != "GET /b" {
+ t.Errorf("dotted tag values = %v, want [GET /a GET /b] (dotted key must round-trip in SQLite mode)", values)
+ }
+}
+
func TestMetricPointRepository_GetAverageBetween(t *testing.T) {
setupTestDB(t)
ctx := context.Background()
diff --git a/backend/app/repositories/profile.repository.go b/backend/app/repositories/profile.repository.go
index ac09317e..0f831c15 100644
--- a/backend/app/repositories/profile.repository.go
+++ b/backend/app/repositories/profile.repository.go
@@ -229,11 +229,12 @@ func (r *profileRepository) GetFlameGraph(ctx context.Context, projectId uuid.UU
func (r *profileRepository) distinctLabelValues(ctx context.Context, projectId uuid.UUID, service, profileType, key string, from, to time.Time) ([]string, error) {
rows, err := chdb.Conn.Query(ctx,
- `SELECT DISTINCT labels[?] AS v
+ fmt.Sprintf(`SELECT DISTINCT labels[?] AS v
FROM profiling_samples
WHERE project_id = ? AND type = ? AND service_name = ? AND start_time >= ? AND start_time <= ?
AND labels[?] != ''
- ORDER BY v ASC`,
+ ORDER BY v ASC
+ LIMIT %d`, profiling.MaxLabelValuesPerKey),
key, projectId, profileType, service, from, to, key)
if err != nil {
return nil, err
diff --git a/backend/app/repositories/profile.repository_labels.go b/backend/app/repositories/profile.repository_labels.go
index 32f6eeed..4957c680 100644
--- a/backend/app/repositories/profile.repository_labels.go
+++ b/backend/app/repositories/profile.repository_labels.go
@@ -2,25 +2,45 @@ package repositories
import (
"context"
+ "sync"
"time"
"github.com/google/uuid"
)
-const profileLabelEndpoint = "endpoint"
+const discoverLabelsTimeout = 10 * time.Second
-var allowedProfileLabels = []string{profileLabelEndpoint}
+func (r *profileRepository) DiscoverLabels(ctx context.Context, projectId uuid.UUID, service, profileType string, from, to time.Time, allowKeys []string) (map[string][]string, error) {
+ ctx, cancel := context.WithTimeout(ctx, discoverLabelsTimeout)
+ defer cancel()
-func (r *profileRepository) DiscoverLabels(ctx context.Context, projectId uuid.UUID, service, profileType string, from, to time.Time) (map[string][]string, error) {
out := map[string][]string{}
- for _, key := range allowedProfileLabels {
- values, err := r.distinctLabelValues(ctx, projectId, service, profileType, key, from, to)
- if err != nil {
- return nil, err
- }
- if len(values) > 0 {
- out[key] = values
- }
+ var mu sync.Mutex
+ var firstErr error
+ var wg sync.WaitGroup
+
+ for _, key := range allowKeys {
+ wg.Add(1)
+ go func(key string) {
+ defer wg.Done()
+ values, err := r.distinctLabelValues(ctx, projectId, service, profileType, key, from, to)
+ mu.Lock()
+ defer mu.Unlock()
+ if err != nil {
+ if firstErr == nil {
+ firstErr = err
+ }
+ return
+ }
+ if len(values) > 0 {
+ out[key] = values
+ }
+ }(key)
+ }
+ wg.Wait()
+
+ if firstErr != nil {
+ return nil, firstErr
}
return out, nil
}
diff --git a/backend/app/repositories/profile.repository_sqlite.go b/backend/app/repositories/profile.repository_sqlite.go
index 3d94985a..16c6c9c0 100644
--- a/backend/app/repositories/profile.repository_sqlite.go
+++ b/backend/app/repositories/profile.repository_sqlite.go
@@ -295,13 +295,14 @@ func (r *profileRepository) GetFlameGraph(ctx context.Context, projectId uuid.UU
func (r *profileRepository) distinctLabelValues(ctx context.Context, projectId uuid.UUID, service, profileType, key string, from, to time.Time) ([]string, error) {
results, err := lit.SelectNamed[labelValueRow](db.TelemetryDB,
- `SELECT DISTINCT json_extract(labels, '$.' || :key) AS v
+ fmt.Sprintf(`SELECT DISTINCT json_extract(labels, '$."' || :key || '"') AS v
FROM profiling_samples
WHERE project_id = :project_id AND type = :type AND service_name = :service
AND start_time >= :from AND start_time <= :to
- AND json_extract(labels, '$.' || :key) IS NOT NULL
- AND json_extract(labels, '$.' || :key) != ''
- ORDER BY v ASC`,
+ AND json_extract(labels, '$."' || :key || '"') IS NOT NULL
+ AND json_extract(labels, '$."' || :key || '"') != ''
+ ORDER BY v ASC
+ LIMIT %d`, profiling.MaxLabelValuesPerKey),
lit.P{"project_id": projectId, "type": profileType, "service": service, "key": key, "from": NewSQLiteTime(from), "to": NewSQLiteTime(to)})
if err != nil {
return nil, err
@@ -329,7 +330,7 @@ func sqliteLabelFilter(qualifier string, filters map[string]string, params lit.P
pathKey := fmt.Sprintf("lblpath_%d", i)
valKey := fmt.Sprintf("lblval_%d", i)
clause += fmt.Sprintf(" AND json_extract(%slabels, :%s) = :%s", qualifier, pathKey, valKey)
- params[pathKey] = "$." + k
+ params[pathKey] = "$.\"" + k + "\""
params[valKey] = filters[k]
}
return clause
diff --git a/backend/app/repositories/profile_labels_test.go b/backend/app/repositories/profile_labels_test.go
index 8a8aab32..154c2d2a 100644
--- a/backend/app/repositories/profile_labels_test.go
+++ b/backend/app/repositories/profile_labels_test.go
@@ -4,6 +4,7 @@ package repositories
import (
"context"
+ "fmt"
"testing"
"time"
@@ -37,7 +38,7 @@ func TestProfileRepository_DiscoverLabels(t *testing.T) {
sample(base, "checkout", profiling.TypeHeapInuseSpace, map[string]string{"endpoint": "/other-type"}),
)
- labels, err := ProfileRepository.DiscoverLabels(ctx, projectId, "checkout", profiling.TypeCPUNanos, from, to)
+ labels, err := ProfileRepository.DiscoverLabels(ctx, projectId, "checkout", profiling.TypeCPUNanos, from, to, profiling.LabelAllowKeys(nil))
if err != nil {
t.Fatalf("DiscoverLabels: %v", err)
}
@@ -68,7 +69,7 @@ func TestProfileRepository_DiscoverLabels_NoValuesOmitsKey(t *testing.T) {
},
)
- labels, err := ProfileRepository.DiscoverLabels(ctx, projectId, "checkout", profiling.TypeCPUNanos, from, to)
+ labels, err := ProfileRepository.DiscoverLabels(ctx, projectId, "checkout", profiling.TypeCPUNanos, from, to, profiling.LabelAllowKeys(nil))
if err != nil {
t.Fatalf("DiscoverLabels: %v", err)
}
@@ -76,3 +77,62 @@ func TestProfileRepository_DiscoverLabels_NoValuesOmitsKey(t *testing.T) {
t.Errorf("a label key with no non-empty values must be omitted, got %v", labels)
}
}
+
+func TestProfileRepository_DiscoverLabels_DottedKey(t *testing.T) {
+ setupTestDB(t)
+ ctx := context.Background()
+ projectId := uuid.New()
+ base := time.Date(2026, 1, 1, 12, 0, 0, 0, time.UTC)
+ from := base.Add(-time.Hour)
+ to := base.Add(time.Hour)
+
+ hashX := profiling.HashFrames([]string{"a"})
+ sample := func(labels map[string]string) models.ProfileSample {
+ return models.ProfileSample{
+ ProjectId: projectId, ProfileId: uuid.New(), ServiceName: "checkout",
+ Type: profiling.TypeCPUNanos, Start: base, End: base, StackHash: hashX, Value: 1, Labels: labels,
+ }
+ }
+ mustInsertSamples(t, ctx,
+ sample(map[string]string{"endpoint": "/x", "http.route": "GET /checkout"}),
+ sample(map[string]string{"endpoint": "/y", "http.route": "GET /cart"}),
+ )
+
+ labels, err := ProfileRepository.DiscoverLabels(ctx, projectId, "checkout", profiling.TypeCPUNanos, from, to, profiling.LabelAllowKeys([]string{"http.route"}))
+ if err != nil {
+ t.Fatalf("DiscoverLabels: %v", err)
+ }
+ routes := labels["http.route"]
+ if len(routes) != 2 || routes[0] != "GET /cart" || routes[1] != "GET /checkout" {
+ t.Errorf("http.route values = %v, want [GET /cart GET /checkout] (dotted key must round-trip in SQLite mode)", routes)
+ }
+}
+
+func TestProfileRepository_DiscoverLabels_LimitsValuesPerKey(t *testing.T) {
+ setupTestDB(t)
+ ctx := context.Background()
+ projectId := uuid.New()
+ base := time.Date(2026, 1, 1, 12, 0, 0, 0, time.UTC)
+ from := base.Add(-time.Hour)
+ to := base.Add(time.Hour)
+
+ hashX := profiling.HashFrames([]string{"a"})
+ total := profiling.MaxLabelValuesPerKey + 50
+ samples := make([]models.ProfileSample, 0, total)
+ for i := range total {
+ samples = append(samples, models.ProfileSample{
+ ProjectId: projectId, ProfileId: uuid.New(), ServiceName: "checkout",
+ Type: profiling.TypeCPUNanos, Start: base, End: base, StackHash: hashX, Value: 1,
+ Labels: map[string]string{"endpoint": fmt.Sprintf("/e%05d", i)},
+ })
+ }
+ mustInsertSamples(t, ctx, samples...)
+
+ labels, err := ProfileRepository.DiscoverLabels(ctx, projectId, "checkout", profiling.TypeCPUNanos, from, to, profiling.LabelAllowKeys(nil))
+ if err != nil {
+ t.Fatalf("DiscoverLabels: %v", err)
+ }
+ if len(labels["endpoint"]) != profiling.MaxLabelValuesPerKey {
+ t.Errorf("endpoint values = %d, want capped at %d", len(labels["endpoint"]), profiling.MaxLabelValuesPerKey)
+ }
+}
diff --git a/backend/app/repositories/profile_query_test.go b/backend/app/repositories/profile_query_test.go
index e4ab14a7..00795661 100644
--- a/backend/app/repositories/profile_query_test.go
+++ b/backend/app/repositories/profile_query_test.go
@@ -140,6 +140,45 @@ func TestProfileRepository_GetFlameGraph_CounterMergesInstancesAndFiltersLabels(
}
}
+func TestProfileRepository_GetFlameGraph_FiltersByDottedLabelKey(t *testing.T) {
+ setupTestDB(t)
+ ctx := context.Background()
+ projectId := uuid.New()
+ base := time.Date(2026, 1, 1, 12, 0, 0, 0, time.UTC)
+ from := base.Add(-time.Hour)
+ to := base.Add(time.Hour)
+
+ hashAB := profiling.HashFrames([]string{"a", "b"})
+ hashAC := profiling.HashFrames([]string{"a", "c"})
+ mustInsertStacks(t, ctx,
+ models.ProfileStack{ProjectId: projectId, ServiceName: "checkout", StackHash: hashAB, Stack: []string{"a", "b"}, LastSeen: base},
+ models.ProfileStack{ProjectId: projectId, ServiceName: "checkout", StackHash: hashAC, Stack: []string{"a", "c"}, LastSeen: base},
+ )
+ cpu := func(hash uint64, value int64, route string) models.ProfileSample {
+ return models.ProfileSample{
+ ProjectId: projectId, ProfileId: uuid.New(), ServiceName: "checkout",
+ Type: profiling.TypeCPUNanos, Start: base, End: base.Add(30 * time.Second),
+ StackHash: hash, Value: value, Labels: map[string]string{"http.route": route},
+ }
+ }
+ mustInsertSamples(t, ctx,
+ cpu(hashAB, 200, "GET /checkout"),
+ cpu(hashAC, 100, "GET /cart"),
+ )
+
+ rows, err := ProfileRepository.GetFlameGraph(ctx, projectId, "checkout", profiling.TypeCPUNanos, from, to, map[string]string{"http.route": "GET /checkout"})
+ if err != nil {
+ t.Fatalf("GetFlameGraph (dotted filter): %v", err)
+ }
+ got := flameValueByStack(rows)
+ if got["a;b"] != 200 {
+ t.Errorf("a;b = %d, want 200 (dotted-key filter must match in SQLite mode)", got["a;b"])
+ }
+ if _, ok := got["a;c"]; ok {
+ t.Errorf("http.route=GET /checkout must exclude the a;c stack, got %v", got)
+ }
+}
+
func TestProfileRepository_GetFlameGraph_GaugeUsesLatestPerServer(t *testing.T) {
setupTestDB(t)
ctx := context.Background()
diff --git a/backend/app/repositories/project.repository.go b/backend/app/repositories/project.repository.go
index 8530451b..cbbc65ed 100644
--- a/backend/app/repositories/project.repository.go
+++ b/backend/app/repositories/project.repository.go
@@ -24,6 +24,7 @@ type projectWithRole struct {
SourceMapToken *string `lit:"source_map_token"`
DropHealthyHealthchecks bool `lit:"drop_healthy_healthchecks"`
HealthcheckPaths models.StringSlice `lit:"healthcheck_paths"`
+ ProfileLabelAllowlist models.StringSlice `lit:"profile_label_allowlist"`
Role string `lit:"role"`
}
@@ -36,7 +37,7 @@ func init() {
func (p *projectRepository) FindAllWithBackendUrlByUserId(tx *sql.Tx, userId int) ([]*models.ProjectWithBackendUrl, error) {
rows, err := lit.SelectNamed[projectWithRole](
tx,
- `SELECT DISTINCT p.id, p.name, p.token, p.framework, p.organization_id, p.created_at, p.source_map_token, p.drop_healthy_healthchecks, p.healthcheck_paths, ou.role
+ `SELECT DISTINCT p.id, p.name, p.token, p.framework, p.organization_id, p.created_at, p.source_map_token, p.drop_healthy_healthchecks, p.healthcheck_paths, p.profile_label_allowlist, ou.role
FROM projects p
INNER JOIN organization_users ou ON p.organization_id = ou.organization_id
WHERE ou.user_id = :user_id
@@ -66,6 +67,7 @@ func (p *projectRepository) FindAllWithBackendUrlByUserId(tx *sql.Tx, userId int
SourceMapToken: sourceMapToken,
DropHealthyHealthchecks: row.DropHealthyHealthchecks,
HealthcheckPaths: row.HealthcheckPaths,
+ ProfileLabelAllowlist: row.ProfileLabelAllowlist,
}
result = append(result, project.ToProjectWithBackendUrl())
}
@@ -76,14 +78,14 @@ func (p *projectRepository) FindAllWithBackendUrlByUserId(tx *sql.Tx, userId int
func (p *projectRepository) FindAll(tx *sql.Tx) ([]*models.Project, error) {
return lit.Select[models.Project](
tx,
- "SELECT id, name, token, framework, organization_id, created_at, source_map_token, drop_healthy_healthchecks, healthcheck_paths FROM projects ORDER BY created_at ASC",
+ "SELECT id, name, token, framework, organization_id, created_at, source_map_token, drop_healthy_healthchecks, healthcheck_paths, profile_label_allowlist FROM projects ORDER BY created_at ASC",
)
}
func (p *projectRepository) FindByToken(tx *sql.Tx, token string) (*models.Project, error) {
return lit.SelectSingleNamed[models.Project](
tx,
- "SELECT id, name, token, framework, organization_id, created_at, source_map_token, drop_healthy_healthchecks, healthcheck_paths FROM projects WHERE token = :token",
+ "SELECT id, name, token, framework, organization_id, created_at, source_map_token, drop_healthy_healthchecks, healthcheck_paths, profile_label_allowlist FROM projects WHERE token = :token",
lit.P{"token": token},
)
}
@@ -91,7 +93,7 @@ func (p *projectRepository) FindByToken(tx *sql.Tx, token string) (*models.Proje
func (p *projectRepository) FindById(tx *sql.Tx, id uuid.UUID) (*models.Project, error) {
return lit.SelectSingleNamed[models.Project](
tx,
- "SELECT id, name, token, framework, organization_id, created_at, source_map_token, drop_healthy_healthchecks, healthcheck_paths FROM projects WHERE id = :id",
+ "SELECT id, name, token, framework, organization_id, created_at, source_map_token, drop_healthy_healthchecks, healthcheck_paths, profile_label_allowlist FROM projects WHERE id = :id",
lit.P{"id": id},
)
}
@@ -123,6 +125,7 @@ func (p *projectRepository) CreateWithOrganization(tx *sql.Tx, name string, fram
OrganizationId: &organizationId,
CreatedAt: time.Now().UTC(),
DropHealthyHealthchecks: true,
+ ProfileLabelAllowlist: models.StringSlice{},
}
if frameworkRequiresSymbolUpload(framework) {
@@ -141,7 +144,7 @@ func (p *projectRepository) CreateWithOrganization(tx *sql.Tx, name string, fram
func (p *projectRepository) FindByOrganizationId(tx *sql.Tx, organizationId int) ([]*models.Project, error) {
return lit.SelectNamed[models.Project](
tx,
- "SELECT id, name, token, framework, organization_id, created_at, source_map_token, drop_healthy_healthchecks, healthcheck_paths FROM projects WHERE organization_id = :org_id ORDER BY created_at ASC",
+ "SELECT id, name, token, framework, organization_id, created_at, source_map_token, drop_healthy_healthchecks, healthcheck_paths, profile_label_allowlist FROM projects WHERE organization_id = :org_id ORDER BY created_at ASC",
lit.P{"org_id": organizationId},
)
}
@@ -149,7 +152,7 @@ func (p *projectRepository) FindByOrganizationId(tx *sql.Tx, organizationId int)
func (p *projectRepository) FindByUserId(tx *sql.Tx, userId int) ([]*models.Project, error) {
return lit.SelectNamed[models.Project](
tx,
- `SELECT DISTINCT p.id, p.name, p.token, p.framework, p.organization_id, p.created_at, p.source_map_token, p.drop_healthy_healthchecks, p.healthcheck_paths
+ `SELECT DISTINCT p.id, p.name, p.token, p.framework, p.organization_id, p.created_at, p.source_map_token, p.drop_healthy_healthchecks, p.healthcheck_paths, p.profile_label_allowlist
FROM projects p
INNER JOIN organization_users ou ON p.organization_id = ou.organization_id
WHERE ou.user_id = :user_id
@@ -195,7 +198,7 @@ func (p *projectRepository) GenerateSourceMapToken(tx *sql.Tx, projectId uuid.UU
return token, nil
}
-func (p *projectRepository) Update(tx *sql.Tx, id uuid.UUID, name string, framework string, dropHealthyHealthchecks *bool, healthcheckPaths *[]string) (*models.Project, error) {
+func (p *projectRepository) Update(tx *sql.Tx, id uuid.UUID, name string, framework string, dropHealthyHealthchecks *bool, healthcheckPaths *[]string, profileLabelAllowlist *[]string) (*models.Project, error) {
project, err := p.FindById(tx, id)
if err != nil {
return nil, err
@@ -211,6 +214,9 @@ func (p *projectRepository) Update(tx *sql.Tx, id uuid.UUID, name string, framew
if healthcheckPaths != nil {
project.HealthcheckPaths = models.StringSlice(*healthcheckPaths)
}
+ if profileLabelAllowlist != nil {
+ project.ProfileLabelAllowlist = models.StringSlice(*profileLabelAllowlist)
+ }
err = lit.UpdateNamed[models.Project](tx, project, "id = :id", lit.P{"id": id})
if err != nil {
return nil, err
@@ -237,7 +243,7 @@ func (p *projectRepository) Delete(tx *sql.Tx, id uuid.UUID) error {
func (p *projectRepository) FindBySourceMapToken(tx *sql.Tx, token string) (*models.Project, error) {
return lit.SelectSingleNamed[models.Project](
tx,
- "SELECT id, name, token, framework, organization_id, created_at, source_map_token, drop_healthy_healthchecks, healthcheck_paths FROM projects WHERE source_map_token = :smt",
+ "SELECT id, name, token, framework, organization_id, created_at, source_map_token, drop_healthy_healthchecks, healthcheck_paths, profile_label_allowlist FROM projects WHERE source_map_token = :smt",
lit.P{"smt": token},
)
}
diff --git a/backend/app/repositories/project.repository_sqlite_test.go b/backend/app/repositories/project.repository_sqlite_test.go
index c84c1c55..f3daf301 100644
--- a/backend/app/repositories/project.repository_sqlite_test.go
+++ b/backend/app/repositories/project.repository_sqlite_test.go
@@ -19,7 +19,8 @@ func setupProjectsTable(t *testing.T) {
source_map_token TEXT,
created_at DATETIME NOT NULL DEFAULT (datetime('now')),
drop_healthy_healthchecks INTEGER NOT NULL DEFAULT 1,
- healthcheck_paths TEXT NOT NULL DEFAULT '[]'
+ healthcheck_paths TEXT NOT NULL DEFAULT '[]',
+ profile_label_allowlist TEXT NOT NULL DEFAULT '[]'
)`)
if err != nil {
t.Fatalf("failed to create projects table: %v", err)
@@ -60,7 +61,8 @@ func TestProjectHealthcheckFieldsRoundTrip(t *testing.T) {
disable := false
paths := []string{"/internal/probe", "/checks/*"}
- updated, err := ProjectRepository.Update(tx, created.Id, "test-project", "gin", &disable, &paths)
+ labels := []string{"tenant", "region"}
+ updated, err := ProjectRepository.Update(tx, created.Id, "test-project", "gin", &disable, &paths, &labels)
if err != nil {
t.Fatalf("failed to update project: %v", err)
}
@@ -78,13 +80,19 @@ func TestProjectHealthcheckFieldsRoundTrip(t *testing.T) {
if len(found.HealthcheckPaths) != 2 || found.HealthcheckPaths[0] != "/internal/probe" || found.HealthcheckPaths[1] != "/checks/*" {
t.Errorf("HealthcheckPaths = %v, expected %v", found.HealthcheckPaths, paths)
}
+ if len(found.ProfileLabelAllowlist) != 2 || found.ProfileLabelAllowlist[0] != "tenant" || found.ProfileLabelAllowlist[1] != "region" {
+ t.Errorf("ProfileLabelAllowlist = %v, expected %v", found.ProfileLabelAllowlist, labels)
+ }
keepDrop := true
- updated, err = ProjectRepository.Update(tx, created.Id, "renamed", "gin", &keepDrop, nil)
+ updated, err = ProjectRepository.Update(tx, created.Id, "renamed", "gin", &keepDrop, nil, nil)
if err != nil {
t.Fatalf("failed to update project without paths: %v", err)
}
if len(updated.HealthcheckPaths) != 2 {
t.Errorf("nil healthcheckPaths should keep existing value, got %v", updated.HealthcheckPaths)
}
+ if len(updated.ProfileLabelAllowlist) != 2 {
+ t.Errorf("nil profileLabelAllowlist should keep existing value, got %v", updated.ProfileLabelAllowlist)
+ }
}
diff --git a/backend/app/repositories/session.repository_sqlite.go b/backend/app/repositories/session.repository_sqlite.go
index ca91525a..6d752c29 100644
--- a/backend/app/repositories/session.repository_sqlite.go
+++ b/backend/app/repositories/session.repository_sqlite.go
@@ -220,14 +220,9 @@ func buildSessionFilterClauseSQLite(search string, filters []SessionAttributeFil
}
keyParam := fmt.Sprintf("attr_k_%d", i)
valParam := fmt.Sprintf("attr_v_%d", i)
- // Build the JSON path inline (key is interpolated into a parameter)
- // using json_extract's `$.path` syntax via concatenation, but SQLite
- // requires the path string itself to be a literal — we build it via
- // `'$.' || :key`. (`json_extract` accepts a path expression as a
- // regular string, not a column reference.)
- sb.WriteString(" AND json_extract(attributes, '$.' || :")
+ sb.WriteString(" AND json_extract(attributes, '$.\"' || :")
sb.WriteString(keyParam)
- sb.WriteString(") = :")
+ sb.WriteString(" || '\"') = :")
sb.WriteString(valParam)
params[keyParam] = f.Key
params[valParam] = f.Value
diff --git a/backend/app/repositories/testhelper_sqlite_test.go b/backend/app/repositories/testhelper_sqlite_test.go
index 8b75604a..751e5044 100644
--- a/backend/app/repositories/testhelper_sqlite_test.go
+++ b/backend/app/repositories/testhelper_sqlite_test.go
@@ -248,6 +248,41 @@ CREATE TABLE IF NOT EXISTS profiles (
distributed_trace_id TEXT DEFAULT NULL
);
CREATE INDEX IF NOT EXISTS idx_profiles_project_recorded ON profiles(project_id, recorded_at);
+
+CREATE TABLE IF NOT EXISTS log_records (
+ id TEXT NOT NULL,
+ project_id TEXT NOT NULL,
+ timestamp DATETIME NOT NULL,
+ trace_id TEXT NOT NULL DEFAULT '',
+ span_id TEXT NOT NULL DEFAULT '',
+ trace_flags INTEGER NOT NULL DEFAULT 0,
+ severity_text TEXT NOT NULL DEFAULT '',
+ severity_number INTEGER NOT NULL DEFAULT 0,
+ service_name TEXT NOT NULL DEFAULT '',
+ body TEXT NOT NULL DEFAULT '',
+ resource_schema_url TEXT NOT NULL DEFAULT '',
+ resource_attributes TEXT NOT NULL DEFAULT '{}',
+ scope_schema_url TEXT NOT NULL DEFAULT '',
+ scope_name TEXT NOT NULL DEFAULT '',
+ scope_version TEXT NOT NULL DEFAULT '',
+ scope_attributes TEXT NOT NULL DEFAULT '{}',
+ log_attributes TEXT NOT NULL DEFAULT '{}'
+);
+CREATE INDEX IF NOT EXISTS idx_log_records_project_timestamp ON log_records(project_id, timestamp);
+
+CREATE TABLE IF NOT EXISTS sessions (
+ id TEXT NOT NULL PRIMARY KEY,
+ project_id TEXT NOT NULL,
+ started_at DATETIME NOT NULL,
+ ended_at DATETIME,
+ duration INTEGER NOT NULL DEFAULT 0,
+ client_ip TEXT NOT NULL DEFAULT '',
+ attributes TEXT NOT NULL DEFAULT '{}',
+ app_version TEXT NOT NULL DEFAULT '',
+ server_name TEXT NOT NULL DEFAULT '',
+ distributed_trace_id TEXT DEFAULT NULL
+);
+CREATE INDEX IF NOT EXISTS idx_sessions_project_started ON sessions(project_id, started_at);
`
statements := splitStatements(ddl)
diff --git a/cli/test/contract/testdata/login.schema.txt b/cli/test/contract/testdata/login.schema.txt
index 094f454d..03e17066 100644
--- a/cli/test/contract/testdata/login.schema.txt
+++ b/cli/test/contract/testdata/login.schema.txt
@@ -10,6 +10,7 @@ projects[].healthcheckPaths[]: empty
projects[].id: string
projects[].name: string
projects[].organizationId: number
+projects[].profileLabelAllowlist[]: empty
projects[].token: string
token: string
user.createdAt: string
diff --git a/cli/test/contract/testdata/projects-list.schema.txt b/cli/test/contract/testdata/projects-list.schema.txt
index 331aa2eb..7e4ba4ef 100644
--- a/cli/test/contract/testdata/projects-list.schema.txt
+++ b/cli/test/contract/testdata/projects-list.schema.txt
@@ -6,4 +6,5 @@
[].id: string
[].name: string
[].organizationId: number
+[].profileLabelAllowlist[]: empty
[].token: string
diff --git a/examples/devtesting-embedded/go.mod b/examples/devtesting-embedded/go.mod
index c1f68995..b4ccafbd 100644
--- a/examples/devtesting-embedded/go.mod
+++ b/examples/devtesting-embedded/go.mod
@@ -65,6 +65,7 @@ require (
github.com/goccy/go-yaml v1.19.2 // indirect
github.com/golang-jwt/jwt/v5 v5.3.0 // indirect
github.com/golang-migrate/migrate/v4 v4.19.1 // indirect
+ github.com/google/pprof v0.0.0-20260604005048-7023385849c0 // indirect
github.com/gorilla/mux v1.7.4 // indirect
github.com/gorilla/securecookie v1.1.2 // indirect
github.com/gorilla/sessions v1.4.0 // indirect
@@ -104,6 +105,8 @@ require (
go.opentelemetry.io/otel/metric v1.44.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.44.0 // indirect
go.opentelemetry.io/proto/otlp v1.10.0 // indirect
+ go.opentelemetry.io/proto/otlp/collector/profiles/v1development v0.3.0 // indirect
+ go.opentelemetry.io/proto/otlp/profiles/v1development v0.3.0 // indirect
go.tracewayapp.com v1.0.4 // indirect
go.tracewayapp.com/tracewaygin v1.0.2 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
diff --git a/examples/devtesting-embedded/go.sum b/examples/devtesting-embedded/go.sum
index af1d5491..b4a0eaaa 100644
--- a/examples/devtesting-embedded/go.sum
+++ b/examples/devtesting-embedded/go.sum
@@ -146,6 +146,8 @@ github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
+github.com/google/pprof v0.0.0-20260604005048-7023385849c0 h1:h1QTMDl6q9wDvDCJVpKQSjgleGFYnd2fOxmg2K+6BGE=
+github.com/google/pprof v0.0.0-20260604005048-7023385849c0/go.mod h1:MxpfABSjhmINe3F1It9d+8exIHFvUqtLIRCdOGNXqiI=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
@@ -310,6 +312,10 @@ go.opentelemetry.io/otel/trace v1.44.0 h1:jxF5CsGYCe74MCRx2X4g7WsY/VBKRqqpNvXlX/
go.opentelemetry.io/otel/trace v1.44.0/go.mod h1:oLl1jrMQAVo6v3GAggN+1VH9VIz9iUSvW53sW1Q8PIE=
go.opentelemetry.io/proto/otlp v1.10.0 h1:IQRWgT5srOCYfiWnpqUYz9CVmbO8bFmKcwYxpuCSL2g=
go.opentelemetry.io/proto/otlp v1.10.0/go.mod h1:/CV4QoCR/S9yaPj8utp3lvQPoqMtxXdzn7ozvvozVqk=
+go.opentelemetry.io/proto/otlp/collector/profiles/v1development v0.3.0 h1:AWBLtJn3ajH399gyOuJdqPsC9w152x3xGVVO/UK3vyM=
+go.opentelemetry.io/proto/otlp/collector/profiles/v1development v0.3.0/go.mod h1:kCdbxyM9kfmv3v4ZQzZ2pACxoQ6lE0IsjP+UcZwQnr4=
+go.opentelemetry.io/proto/otlp/profiles/v1development v0.3.0 h1:ZQs05qo3Yh4KUHeVH6v89xErwmsvgA/cLX2/w5Ikp+k=
+go.opentelemetry.io/proto/otlp/profiles/v1development v0.3.0/go.mod h1:3iiRVKaCfVo0UI1ZaSMm5WbCBbINRqVlD9SUmvyBNrY=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y=
diff --git a/frontend/src/lib/components/edit-project-modal.svelte b/frontend/src/lib/components/edit-project-modal.svelte
index e8dc6a58..58927bb9 100644
--- a/frontend/src/lib/components/edit-project-modal.svelte
+++ b/frontend/src/lib/components/edit-project-modal.svelte
@@ -23,12 +23,15 @@
const tabTriggerClass = "-mb-px rounded-none border-b-2 border-transparent bg-transparent px-0 pb-2.5 pt-0 text-sm font-medium text-muted-foreground shadow-none data-[state=active]:border-primary data-[state=active]:bg-transparent data-[state=active]:text-foreground data-[state=active]:shadow-none";
+ const PROFILE_LABEL_KEY_REGEX = /^[a-zA-Z0-9._:-]+$/;
+
let activeTab = $state('project');
let projectName = $state('');
let selectedFramework = $state<Framework>('gin');
let dropHealthyHealthchecks = $state(true);
let healthcheckPathsText = $state('');
let showDefaultHealthcheckPaths = $state(false);
+ let profileLabelsText = $state('');
let loading = $state(false);
let error = $state('');
let showDeleteConfirm = $state(false);
@@ -43,6 +46,7 @@
selectedFramework = project.framework;
dropHealthyHealthchecks = project.dropHealthyHealthchecks ?? true;
healthcheckPathsText = (project.healthcheckPaths ?? []).join('\n');
+ profileLabelsText = (project.profileLabelAllowlist ?? []).join('\n');
error = '';
}
});
@@ -67,10 +71,35 @@
let subtitle = $derived(
activeTab === 'healthchecks' ? 'Control which healthcheck requests are stored.'
+ : activeTab === 'profiles' ? 'Choose which pprof sample labels are recorded and searchable.'
: activeTab === 'danger' ? 'Irreversible and destructive actions.'
: ''
);
+ let profileLabelKeys = $derived(
+ profileLabelsText
+ .split('\n')
+ .map((p) => p.trim())
+ .filter((p) => p.length > 0)
+ );
+
+ let profileLabelError = $derived.by(() => {
+ const keys = profileLabelKeys;
+ if (keys.length > 20) {
+ return 'At most 20 profile label keys are allowed.';
+ }
+ for (const key of keys) {
+ if (key.toLowerCase() === 'endpoint') continue;
+ if (key.length > 100) {
+ return 'Profile label keys must be at most 100 characters.';
+ }
+ if (!PROFILE_LABEL_KEY_REGEX.test(key)) {
+ return `"${key}" may only contain letters, numbers, and . _ : -`;
+ }
+ }
+ return '';
+ });
+
async function handleSubmit(e: Event) {
e.preventDefault();
if (!projectName.trim()) {
@@ -87,8 +116,13 @@
.map(p => p.trim())
.filter(p => p.length > 0);
+ const profileLabelAllowlist = profileLabelsText
+ .split('\n')
+ .map(p => p.trim())
+ .filter(p => p.length > 0);
+
try {
- await projectsState.updateProject(project.id, projectName.trim(), selectedFramework, dropHealthyHealthchecks, healthcheckPaths);
+ await projectsState.updateProject(project.id, projectName.trim(), selectedFramework, dropHealthyHealthchecks, healthcheckPaths, profileLabelAllowlist);
toast.success('Successfully updated the project', { position: 'top-center' });
onOpenChange(false);
} catch (err: any) {
@@ -132,6 +166,7 @@
<Tabs.List class="h-auto w-full justify-start gap-4 rounded-none border-b bg-transparent p-0 pl-6 pt-0">
<Tabs.Trigger value="project" class={tabTriggerClass}>Project</Tabs.Trigger>
<Tabs.Trigger value="healthchecks" class={tabTriggerClass}>Healthchecks</Tabs.Trigger>
+ <Tabs.Trigger value="profiles" class={tabTriggerClass}>Profiles</Tabs.Trigger>
<Tabs.Trigger value="danger" class={tabTriggerClass}>Danger Zone</Tabs.Trigger>
</Tabs.List>
</Tabs.Root>
@@ -184,7 +219,7 @@
Select your framework for tailored integration code
</p>
</div>
- {:else}
+ {:else if activeTab === 'healthchecks'}
<div class="flex items-start gap-2">
<Checkbox
checked={dropHealthyHealthchecks}
@@ -231,6 +266,40 @@
</p>
</div>
{/if}
+ {:else if activeTab === 'profiles'}
+ <div class="space-y-2">
+ <Label>Built-in label</Label>
+ <div class="flex flex-wrap gap-1">
+ <code class="rounded bg-muted px-1.5 py-0.5 text-xs">endpoint</code>
+ </div>
+ <p class="text-xs text-muted-foreground">
+ The <code class="rounded bg-muted px-1 py-0.5 text-[0.7rem]">endpoint</code> label is always recorded and searchable.
+ </p>
+ </div>
+
+ <div class="space-y-2">
+ <Label for="edit-profile-labels">Additional profile labels</Label>
+ <textarea
+ id="edit-profile-labels"
+ bind:value={profileLabelsText}
+ disabled={loading}
+ rows="3"
+ placeholder={"tenant\nregion"}
+ class="border-input bg-background dark:bg-input/30 placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 flex w-full rounded-md border px-3 py-2 text-sm shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50"
+ ></textarea>
+ {#if profileLabelError}
+ <p class="text-xs text-destructive flex items-center gap-1">
+ <CircleAlert class="h-3.5 w-3.5 shrink-0" />
+ {profileLabelError}
+ </p>
+ {/if}
+ <p class="text-xs text-muted-foreground">
+ One label key per line. These pprof sample labels are recorded at ingest and become searchable on the flame-graph page. Added keys only apply to profiles ingested afterward.
+ </p>
+ <p class="text-xs text-muted-foreground">
+ Avoid high-cardinality keys like <code class="rounded bg-muted px-1 py-0.5 text-[0.7rem]">user_id</code> or <code class="rounded bg-muted px-1 py-0.5 text-[0.7rem]">request_id</code>: every distinct value is stored as a separate sample, which bloats storage and slows queries.
+ </p>
+ </div>
{/if}
<div class="flex justify-end gap-2 pt-2">
diff --git a/frontend/src/lib/components/profiles/profile-label-selector.svelte b/frontend/src/lib/components/profiles/profile-label-selector.svelte
deleted file mode 100644
index b23c0d90..00000000
--- a/frontend/src/lib/components/profiles/profile-label-selector.svelte
+++ /dev/null
@@ -1,59 +0,0 @@
-<script module lang="ts">
- export function applyLabel(
- selected: Record<string, string>,
- key: string,
- value: string | undefined
- ): Record<string, string> {
- const next = { ...selected };
- if (value === undefined) {
- delete next[key];
- } else {
- next[key] = value;
- }
- return next;
- }
-
- export function labelTriggerLabel(key: string, value: string | undefined): string {
- return value ? `${key}: ${value}` : `All ${key}`;
- }
-</script>
-
-<script lang="ts">
- import * as Select from '$lib/components/ui/select';
-
- const ALL = '__all__';
-
- let {
- labels,
- selected,
- onSelect
- }: {
- labels: Record<string, string[]>;
- selected: Record<string, string>;
- onSelect: (key: string, value: string | undefined) => void;
- } = $props();
-
- const keys = $derived(Object.keys(labels).sort());
-</script>
-
-{#if keys.length > 0}
- <div class="flex flex-wrap items-center gap-2">
- {#each keys as key (key)}
- <Select.Root
- type="single"
- value={selected[key] ?? ALL}
- onValueChange={(v) => onSelect(key, v === ALL ? undefined : v)}
- >
- <Select.Trigger class="h-9 w-[220px]">
- {labelTriggerLabel(key, selected[key])}
- </Select.Trigger>
- <Select.Content>
- <Select.Item value={ALL}>All {key}</Select.Item>
- {#each labels[key] as value (value)}
- <Select.Item {value} label={value}>{value}</Select.Item>
- {/each}
- </Select.Content>
- </Select.Root>
- {/each}
- </div>
-{/if}
diff --git a/frontend/src/lib/components/profiles/profile-label-selector.test.ts b/frontend/src/lib/components/profiles/profile-label-selector.test.ts
deleted file mode 100644
index 643170ea..00000000
--- a/frontend/src/lib/components/profiles/profile-label-selector.test.ts
+++ /dev/null
@@ -1,74 +0,0 @@
-import { describe, it, expect, vi } from 'vitest';
-import { render } from '@testing-library/svelte';
-
-import ProfileLabelSelector, { applyLabel, labelTriggerLabel } from './profile-label-selector.svelte';
-
-describe('applyLabel', () => {
- it('sets the value for a key', () => {
- expect(applyLabel({}, 'endpoint', 'GET /a')).toEqual({ endpoint: 'GET /a' });
- });
-
- it('replaces an existing value and leaves other keys untouched', () => {
- expect(applyLabel({ endpoint: 'GET /a', region: 'eu' }, 'endpoint', 'GET /b')).toEqual({
- endpoint: 'GET /b',
- region: 'eu'
- });
- });
-
- it('removes the key when the value is undefined', () => {
- expect(applyLabel({ endpoint: 'GET /a', region: 'eu' }, 'endpoint', undefined)).toEqual({
- region: 'eu'
- });
- });
-
- it('does not mutate the input map', () => {
- const selected = { endpoint: 'GET /a' };
- applyLabel(selected, 'region', 'eu');
- expect(selected).toEqual({ endpoint: 'GET /a' });
- });
-});
-
-describe('labelTriggerLabel', () => {
- it('shows the key and value when a value is selected', () => {
- expect(labelTriggerLabel('endpoint', 'GET /a')).toBe('endpoint: GET /a');
- });
-
- it('shows an all-values placeholder when nothing is selected', () => {
- expect(labelTriggerLabel('endpoint', undefined)).toBe('All endpoint');
- });
-});
-
-describe('ProfileLabelSelector component', () => {
- function triggers(container: HTMLElement) {
- return container.querySelectorAll('[data-slot="select-trigger"]');
- }
-
- it('renders nothing when there are no label keys', () => {
- const { container } = render(ProfileLabelSelector, {
- props: { labels: {}, selected: {}, onSelect: vi.fn() }
- });
- expect(triggers(container)).toHaveLength(0);
- });
-
- it('renders one dropdown per label key', () => {
- const { container } = render(ProfileLabelSelector, {
- props: {
- labels: { endpoint: ['GET /a', 'GET /b'], region: ['eu', 'us'] },
- selected: {},
- onSelect: vi.fn()
- }
- });
- expect(triggers(container)).toHaveLength(2);
- });
-
- it('shows the selected value in the trigger', () => {
- const { getByText } = render(ProfileLabelSelector, {
- props: {
- labels: { endpoint: ['GET /a', 'GET /b'] },
- selected: { endpoint: 'GET /b' },
- onSelect: vi.fn()
- }
- });
- expect(getByText('endpoint: GET /b')).toBeTruthy();
- });
-});
diff --git a/frontend/src/lib/state/projects.svelte.ts b/frontend/src/lib/state/projects.svelte.ts
index 00d5ca0c..ca9cc904 100644
--- a/frontend/src/lib/state/projects.svelte.ts
+++ b/frontend/src/lib/state/projects.svelte.ts
@@ -80,6 +80,7 @@ export interface Project {
backendUrl: string;
dropHealthyHealthchecks: boolean;
healthcheckPaths: string[] | null;
+ profileLabelAllowlist: string[] | null;
}
export interface ProjectWithToken extends Project {
@@ -162,8 +163,8 @@ class ProjectsState {
return response;
}
- async updateProject(id: string, name: string, framework: Framework, dropHealthyHealthchecks: boolean, healthcheckPaths: string[]): Promise<Project> {
- const response = await api.put('/projects', { name, framework, dropHealthyHealthchecks, healthcheckPaths }, {
+ async updateProject(id: string, name: string, framework: Framework, dropHealthyHealthchecks: boolean, healthcheckPaths: string[], profileLabelAllowlist: string[]): Promise<Project> {
+ const response = await api.put('/projects', { name, framework, dropHealthyHealthchecks, healthcheckPaths, profileLabelAllowlist }, {
projectId: id
});
await this.loadProjects();
diff --git a/frontend/src/routes/profiles/[service]/+page.svelte b/frontend/src/routes/profiles/[service]/+page.svelte
index d47ffe69..2035ea95 100644
--- a/frontend/src/routes/profiles/[service]/+page.svelte
+++ b/frontend/src/routes/profiles/[service]/+page.svelte
@@ -12,9 +12,7 @@
import { projectsState } from '$lib/state/projects.svelte';
import PageHeader from '$lib/components/issues/page-header.svelte';
import FlameGraph from '$lib/components/profiles/flame-graph.svelte';
- import ProfileLabelSelector, {
- applyLabel
- } from '$lib/components/profiles/profile-label-selector.svelte';
+ import TagFilter from '$lib/components/dashboard/tag-filter.svelte';
import { CalendarDate } from '@internationalized/date';
import {
PROFILE_TYPES,
@@ -136,8 +134,8 @@
loadData(true);
}
- function handleLabelSelect(key: string, value: string | undefined) {
- selectedLabels = applyLabel(selectedLabels, key, value);
+ function handleFilterChange(filters: Record<string, string>) {
+ selectedLabels = filters;
loadData(true);
}
@@ -243,10 +241,11 @@
</Tabs.List>
</Tabs.Root>
- <ProfileLabelSelector
- labels={availableLabels}
- selected={selectedLabels}
- onSelect={handleLabelSelect}
+ <TagFilter
+ tagKeys={Object.keys(availableLabels)}
+ activeFilters={selectedLabels}
+ onFilterChange={handleFilterChange}
+ onLoadTagValues={(key) => Promise.resolve(availableLabels[key] ?? [])}
/>
{#if loading}