Skip to content
Draft
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
8 changes: 8 additions & 0 deletions api-contracts/openapi/components/schemas/_index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -400,3 +400,11 @@ V1CELDebugResponse:
$ref: "./v1/cel.yaml#/V1CELDebugResponse"
V1CELDebugResponseStatus:
$ref: "./v1/cel.yaml#/V1CELDebugResponseStatus"
OtelSpan:
$ref: "./v1/otel.yaml#/OtelSpan"
OtelSpanKind:
$ref: "./v1/otel.yaml#/OtelSpanKind"
OtelStatusCode:
$ref: "./v1/otel.yaml#/OtelStatusCode"
OtelSpanList:
$ref: "./v1/otel.yaml#/OtelSpanList"
73 changes: 73 additions & 0 deletions api-contracts/openapi/components/schemas/v1/otel.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
OtelSpan:
type: object
properties:
trace_id:
type: string
span_id:
type: string
parent_span_id:
type: string
span_name:
type: string
span_kind:
$ref: "#/OtelSpanKind"
service_name:
type: string
status_code:
$ref: "#/OtelStatusCode"
status_message:
type: string
duration:
type: integer
format: int64
created_at:
type: string
format: date-time
resource_attributes:
type: object
additionalProperties:
type: string
span_attributes:
type: object
additionalProperties:
type: string
scope_name:
type: string
scope_version:
type: string
required:
- trace_id
- span_id
- span_name
- span_kind
- service_name
- status_code
- duration
- created_at

OtelSpanKind:
type: string
enum:
- UNSPECIFIED
- INTERNAL
- SERVER
- CLIENT
- PRODUCER
- CONSUMER

OtelStatusCode:
type: string
enum:
- UNSET
- OK
- ERROR

OtelSpanList:
type: object
properties:
pagination:
$ref: "../metadata.yaml#/PaginationResponse"
rows:
type: array
items:
$ref: "#/OtelSpan"
2 changes: 2 additions & 0 deletions api-contracts/openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ paths:
$ref: "./paths/v1/tasks/tasks.yaml#/listTaskEvents"
/api/v1/stable/tasks/{task}/logs:
$ref: "./paths/v1/tasks/tasks.yaml#/listLogs"
/api/v1/stable/tasks/{task}/trace:
$ref: "./paths/v1/tasks/tasks.yaml#/getTrace"
/api/v1/stable/tenants/{tenant}/tasks/cancel:
$ref: "./paths/v1/tasks/tasks.yaml#/cancelTasks"
/api/v1/stable/tenants/{tenant}/tasks/replay:
Expand Down
58 changes: 58 additions & 0 deletions api-contracts/openapi/paths/v1/tasks/tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,64 @@ replayTasks:
tags:
- Task

getTrace:
get:
x-resources: ["tenant", "task"]
description: Get OTel trace for a task run
operationId: v1-task:get:trace
parameters:
- description: The task id
in: path
name: task
required: true
schema:
type: string
format: uuid
minLength: 36
maxLength: 36
- description: The number to skip
in: query
name: offset
required: false
schema:
type: integer
format: int64
- description: The number to limit by
in: query
name: limit
required: false
schema:
type: integer
format: int64
responses:
"200":
content:
application/json:
schema:
$ref: "../../../components/schemas/_index.yaml#/OtelSpanList"
description: Successfully retrieved the OTel trace
"400":
content:
application/json:
schema:
$ref: "../../../components/schemas/_index.yaml#/APIErrors"
description: A malformed or bad request
"403":
content:
application/json:
schema:
$ref: "../../../components/schemas/_index.yaml#/APIErrors"
description: Forbidden
"404":
content:
application/json:
schema:
$ref: "../../../components/schemas/_index.yaml#/APIErrors"
description: The task was not found
summary: Get OTel trace
tags:
- Task

listLogs:
get:
x-resources: ["tenant", "task"]
Expand Down
31 changes: 31 additions & 0 deletions api/v1/server/handlers/v1/tasks/trace.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package tasks

import (
"github.com/labstack/echo/v4"

"github.com/hatchet-dev/hatchet/api/v1/server/oas/gen"
transformers "github.com/hatchet-dev/hatchet/api/v1/server/oas/transformers/v1"
"github.com/hatchet-dev/hatchet/pkg/repository/sqlcv1"
)

func (t *TasksService) V1TaskGetTrace(ctx echo.Context, request gen.V1TaskGetTraceRequestObject) (gen.V1TaskGetTraceResponseObject, error) {
task := ctx.Get("task").(*sqlcv1.V1TasksOlap)

limit := int64(1000)
offset := int64(0)

if request.Params.Limit != nil {
limit = *request.Params.Limit
}

if request.Params.Offset != nil {
offset = *request.Params.Offset
}

result, err := t.config.V1.OTelCollector().ListSpansByTaskExternalID(ctx.Request().Context(), task.TenantID, task.ExternalID, offset, limit)
if err != nil {
return nil, err
}

return gen.V1TaskGetTrace200JSONResponse(transformers.ToV1OtelSpanList(result.Rows, limit, offset, result.Total)), nil
}
Loading
Loading