|
5 | 5 | "time" |
6 | 6 |
|
7 | 7 | "github.com/posthog/posthog-go" |
8 | | - "go.opentelemetry.io/otel/attribute" |
9 | 8 | "go.opentelemetry.io/otel/metric" |
10 | 9 | "go.uber.org/zap" |
11 | 10 | "google.golang.org/protobuf/types/known/timestamppb" |
@@ -113,45 +112,41 @@ func (o *Orchestrator) analyticsRemove(ctx context.Context, sandbox sandbox.Sand |
113 | 112 | } |
114 | 113 | } |
115 | 114 |
|
116 | | -func (o *Orchestrator) analyticsInsert(ctx context.Context, sandbox sandbox.Sandbox, created bool) { |
| 115 | +func (o *Orchestrator) analyticsInsert(ctx context.Context, sandbox sandbox.Sandbox) { |
117 | 116 | ctx, cancel := context.WithTimeout(ctx, reportTimeout) |
118 | 117 | defer cancel() |
119 | 118 |
|
120 | | - if created { |
121 | | - // Run in separate goroutine to not block sandbox creation |
122 | | - _, err := o.analytics.InstanceStarted(ctx, &analyticscollector.InstanceStartedEvent{ |
123 | | - InstanceId: sandbox.SandboxID, |
124 | | - ExecutionId: sandbox.ExecutionID, |
125 | | - EnvironmentId: sandbox.TemplateID, |
126 | | - BuildId: sandbox.BuildID.String(), |
127 | | - TeamId: sandbox.TeamID.String(), |
128 | | - CpuCount: sandbox.VCpu, |
129 | | - RamMb: sandbox.RamMB, |
130 | | - DiskSizeMb: sandbox.TotalDiskSizeMB, |
131 | | - Timestamp: timestamppb.Now(), |
132 | | - }) |
133 | | - if err != nil { |
134 | | - logger.L().Error(ctx, "Error sending Analytics event", zap.Error(err)) |
135 | | - } |
| 119 | + _, err := o.analytics.InstanceStarted(ctx, &analyticscollector.InstanceStartedEvent{ |
| 120 | + InstanceId: sandbox.SandboxID, |
| 121 | + ExecutionId: sandbox.ExecutionID, |
| 122 | + EnvironmentId: sandbox.TemplateID, |
| 123 | + BuildId: sandbox.BuildID.String(), |
| 124 | + TeamId: sandbox.TeamID.String(), |
| 125 | + CpuCount: sandbox.VCpu, |
| 126 | + RamMb: sandbox.RamMB, |
| 127 | + DiskSizeMb: sandbox.TotalDiskSizeMB, |
| 128 | + Timestamp: timestamppb.Now(), |
| 129 | + }) |
| 130 | + if err != nil { |
| 131 | + logger.L().Error(ctx, "Error sending Analytics event", zap.Error(err)) |
136 | 132 | } |
137 | 133 | } |
138 | 134 |
|
139 | | -func (o *Orchestrator) countersInsert(ctx context.Context, sandbox sandbox.Sandbox, newlyCreated bool) { |
140 | | - attributes := []attribute.KeyValue{ |
141 | | - telemetry.WithTeamID(sandbox.TeamID.String()), |
142 | | - } |
| 135 | +func (o *Orchestrator) handleNewlyCreatedSandbox(ctx context.Context, sandbox sandbox.Sandbox) { |
| 136 | + // Send analytics event |
| 137 | + o.analyticsInsert(ctx, sandbox) |
143 | 138 |
|
144 | | - if newlyCreated { |
145 | | - o.createdCounter.Add(ctx, 1, metric.WithAttributes(attributes...)) |
146 | | - } |
| 139 | + // Update team metrics |
| 140 | + o.teamMetricsObserver.Add(ctx, sandbox.TeamID) |
147 | 141 |
|
148 | | - o.sandboxCounter.Add(ctx, 1, metric.WithAttributes(attributes...)) |
| 142 | + // Increment created counter |
| 143 | + o.createdCounter.Add(ctx, 1, metric.WithAttributes(telemetry.WithTeamID(sandbox.TeamID.String()))) |
149 | 144 | } |
150 | 145 |
|
151 | | -func (o *Orchestrator) countersRemove(ctx context.Context, sandbox sandbox.Sandbox, _ sandbox.StateAction) { |
152 | | - attributes := []attribute.KeyValue{ |
153 | | - telemetry.WithTeamID(sandbox.TeamID.String()), |
154 | | - } |
| 146 | +func (o *Orchestrator) sandboxCounterInsert(ctx context.Context, sandbox sandbox.Sandbox) { |
| 147 | + o.sandboxCounter.Add(ctx, 1, metric.WithAttributes(telemetry.WithTeamID(sandbox.TeamID.String()))) |
| 148 | +} |
155 | 149 |
|
156 | | - o.sandboxCounter.Add(ctx, -1, metric.WithAttributes(attributes...)) |
| 150 | +func (o *Orchestrator) countersRemove(ctx context.Context, sandbox sandbox.Sandbox, _ sandbox.StateAction) { |
| 151 | + o.sandboxCounter.Add(ctx, -1, metric.WithAttributes(telemetry.WithTeamID(sandbox.TeamID.String()))) |
157 | 152 | } |
0 commit comments