mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2025-12-16 22:35:11 -06:00
instrument tenant id attribute
This commit is contained in:
@@ -7,9 +7,13 @@ import (
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/labstack/echo/v4"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
|
||||
"github.com/hatchet-dev/hatchet/api/v1/server/middleware"
|
||||
"github.com/hatchet-dev/hatchet/pkg/config/server"
|
||||
"github.com/hatchet-dev/hatchet/pkg/repository/postgres/dbsqlc"
|
||||
"github.com/hatchet-dev/hatchet/pkg/telemetry"
|
||||
"github.com/hatchet-dev/hatchet/pkg/telemetry/servertel"
|
||||
)
|
||||
|
||||
type ResourceGetterFunc func(config *server.ServerConfig, parentId, id string) (result interface{}, uniqueParentId string, err error)
|
||||
@@ -102,6 +106,17 @@ func (p *Populator) populate(c echo.Context, r *middleware.RouteInfo) error {
|
||||
currResource = currResource.Children[0]
|
||||
}
|
||||
|
||||
// If we populated a tenant (or have the tenant id in the route params), attach it to the active trace
|
||||
// span so downstream traces are tenant-attributable.
|
||||
ctx := c.Request().Context()
|
||||
span := trace.SpanFromContext(ctx)
|
||||
|
||||
if tenant, ok := c.Get("tenant").(*dbsqlc.Tenant); ok && tenant != nil {
|
||||
telemetry.WithAttributes(span, servertel.TenantId(tenant.ID))
|
||||
} else if tenantId := c.Param("tenant"); tenantId != "" {
|
||||
telemetry.WithAttributes(span, telemetry.AttributeKV{Key: "tenant.id", Value: tenantId})
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user