|
|
@@ -11,6 +11,7 @@ import (
|
|
|
"github.com/porter-dev/porter/api/types"
|
|
|
porter_agent "github.com/porter-dev/porter/internal/kubernetes/porter_agent/v2"
|
|
|
"github.com/porter-dev/porter/internal/models"
|
|
|
+ "github.com/porter-dev/porter/internal/telemetry"
|
|
|
)
|
|
|
|
|
|
type GetLogsHandler struct {
|
|
|
@@ -30,6 +31,9 @@ func NewGetLogsHandler(
|
|
|
}
|
|
|
|
|
|
func (c *GetLogsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
|
+ ctx, span := telemetry.NewSpan(r.Context(), "serve-get-logs")
|
|
|
+ defer span.End()
|
|
|
+
|
|
|
cluster, _ := r.Context().Value(types.ClusterScope).(*models.Cluster)
|
|
|
|
|
|
request := &types.GetLogRequest{}
|
|
|
@@ -38,6 +42,18 @@ func (c *GetLogsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ telemetry.WithAttributes(span,
|
|
|
+ telemetry.AttributeKV{Key: "cluster-id", Value: cluster.ID},
|
|
|
+ telemetry.AttributeKV{Key: "limit", Value: request.Limit},
|
|
|
+ telemetry.AttributeKV{Key: "start-range", Value: request.StartRange},
|
|
|
+ telemetry.AttributeKV{Key: "end-range", Value: request.EndRange},
|
|
|
+ telemetry.AttributeKV{Key: "search-param", Value: request.SearchParam},
|
|
|
+ telemetry.AttributeKV{Key: "revision", Value: request.Revision},
|
|
|
+ telemetry.AttributeKV{Key: "pod-selector", Value: request.PodSelector},
|
|
|
+ telemetry.AttributeKV{Key: "namespace", Value: request.Namespace},
|
|
|
+ telemetry.AttributeKV{Key: "direction", Value: request.Direction},
|
|
|
+ )
|
|
|
+
|
|
|
agent, err := c.GetAgent(r, cluster, "")
|
|
|
if err != nil {
|
|
|
c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
|
|
|
@@ -47,13 +63,15 @@ func (c *GetLogsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
|
// get agent service
|
|
|
agentSvc, err := porter_agent.GetAgentService(agent.Clientset)
|
|
|
if err != nil {
|
|
|
- c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
|
|
|
+ err = telemetry.Error(ctx, span, err, "unable to get agent service")
|
|
|
+ c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusInternalServerError))
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- logs, err := porter_agent.GetHistoricalLogs(agent.Clientset, agentSvc, request)
|
|
|
+ logs, err := porter_agent.GetHistoricalLogs(ctx, agent.Clientset, agentSvc, request)
|
|
|
if err != nil {
|
|
|
- c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
|
|
|
+ err = telemetry.Error(ctx, span, err, "unable to get historical logs")
|
|
|
+ c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusInternalServerError))
|
|
|
return
|
|
|
}
|
|
|
|