-
Notifications
You must be signed in to change notification settings - Fork 11
chore: add tracing to all events #672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,65 +1,146 @@ | ||
| import type { Event } from "@ctrlplane/events"; | ||
|
|
||
| import { makeWithSpan, trace } from "@ctrlplane/logger"; | ||
|
|
||
| import type { Handler } from "."; | ||
| import { OperationPipeline } from "../workspace/pipeline.js"; | ||
| import { WorkspaceManager } from "../workspace/workspace.js"; | ||
|
|
||
| export const newDeploymentVariable: Handler< | ||
| Event.DeploymentVariableCreated | ||
| > = async (event) => { | ||
| const ws = await WorkspaceManager.getOrLoad(event.workspaceId); | ||
| if (ws == null) return; | ||
| await OperationPipeline.update(ws) | ||
| .deploymentVariable(event.payload) | ||
| .dispatch(); | ||
| }; | ||
| const newDeploymentVariableTracer = trace.getTracer("new-deployment-variable"); | ||
| const withNewDeploymentVariableSpan = makeWithSpan(newDeploymentVariableTracer); | ||
|
|
||
| export const newDeploymentVariable: Handler<Event.DeploymentVariableCreated> = | ||
| withNewDeploymentVariableSpan( | ||
| "new-deployment-variable", | ||
| async (span, event) => { | ||
| span.setAttribute("event.type", event.eventType); | ||
| span.setAttribute("deployment-variable.id", event.payload.id); | ||
| span.setAttribute("deployment.id", event.payload.deploymentId); | ||
| span.setAttribute("workspace.id", event.workspaceId); | ||
| const ws = await WorkspaceManager.getOrLoad(event.workspaceId); | ||
| if (ws == null) return; | ||
| await OperationPipeline.update(ws) | ||
| .deploymentVariable(event.payload) | ||
| .dispatch(); | ||
| }, | ||
| ); | ||
|
|
||
| const updatedDeploymentVariableTracer = trace.getTracer( | ||
| "updated-deployment-variable", | ||
| ); | ||
| const withUpdatedDeploymentVariableSpan = makeWithSpan( | ||
| updatedDeploymentVariableTracer, | ||
| ); | ||
|
|
||
| export const updatedDeploymentVariable: Handler<Event.DeploymentVariableUpdated> = | ||
| withUpdatedDeploymentVariableSpan( | ||
| "updated-deployment-variable", | ||
| async (span, event) => { | ||
| span.setAttribute("event.type", event.eventType); | ||
| span.setAttribute("deployment-variable.id", event.payload.current.id); | ||
| span.setAttribute("deployment.id", event.payload.current.deploymentId); | ||
| span.setAttribute("workspace.id", event.workspaceId); | ||
| const ws = await WorkspaceManager.getOrLoad(event.workspaceId); | ||
| if (ws == null) return; | ||
| await OperationPipeline.update(ws) | ||
| .deploymentVariable(event.payload.current) | ||
| .dispatch(); | ||
| }, | ||
| ); | ||
|
|
||
| const deletedDeploymentVariableTracer = trace.getTracer( | ||
| "deleted-deployment-variable", | ||
| ); | ||
| const withDeletedDeploymentVariableSpan = makeWithSpan( | ||
| deletedDeploymentVariableTracer, | ||
| ); | ||
|
|
||
| export const deletedDeploymentVariable: Handler<Event.DeploymentVariableDeleted> = | ||
| withDeletedDeploymentVariableSpan( | ||
| "deleted-deployment-variable", | ||
| async (span, event) => { | ||
| span.setAttribute("event.type", event.eventType); | ||
| span.setAttribute("deployment-variable.id", event.payload.id); | ||
| span.setAttribute("deployment.id", event.payload.deploymentId); | ||
| span.setAttribute("workspace.id", event.workspaceId); | ||
| const ws = await WorkspaceManager.getOrLoad(event.workspaceId); | ||
| if (ws == null) return; | ||
| await OperationPipeline.delete(ws) | ||
| .deploymentVariable(event.payload) | ||
| .dispatch(); | ||
| }, | ||
| ); | ||
|
|
||
| const newDeploymentVariableValueTracer = trace.getTracer( | ||
| "new-deployment-variable-value", | ||
| ); | ||
| const withNewDeploymentVariableValueSpan = makeWithSpan( | ||
| newDeploymentVariableValueTracer, | ||
| ); | ||
|
|
||
| export const updatedDeploymentVariable: Handler< | ||
| Event.DeploymentVariableUpdated | ||
| > = async (event) => { | ||
| const ws = await WorkspaceManager.getOrLoad(event.workspaceId); | ||
| if (ws == null) return; | ||
| await OperationPipeline.update(ws) | ||
| .deploymentVariable(event.payload.current) | ||
| .dispatch(); | ||
| }; | ||
| export const newDeploymentVariableValue: Handler<Event.DeploymentVariableValueCreated> = | ||
| withNewDeploymentVariableValueSpan( | ||
| "new-deployment-variable-value", | ||
| async (span, event) => { | ||
| span.setAttribute("deployment-variable-value.id", event.payload.id); | ||
| span.setAttribute("deployment-variable.id", event.payload.variableId); | ||
| span.setAttribute("workspace.id", event.workspaceId); | ||
| const ws = await WorkspaceManager.getOrLoad(event.workspaceId); | ||
| if (ws == null) return; | ||
| await OperationPipeline.update(ws) | ||
| .deploymentVariableValue(event.payload) | ||
| .dispatch(); | ||
| }, | ||
| ); | ||
|
|
||
| export const deletedDeploymentVariable: Handler< | ||
| Event.DeploymentVariableDeleted | ||
| > = async (event) => { | ||
| const ws = await WorkspaceManager.getOrLoad(event.workspaceId); | ||
| if (ws == null) return; | ||
| await OperationPipeline.update(ws) | ||
| .deploymentVariable(event.payload) | ||
| .dispatch(); | ||
| }; | ||
| const updatedDeploymentVariableValueTracer = trace.getTracer( | ||
| "updated-deployment-variable-value", | ||
| ); | ||
| const withUpdatedDeploymentVariableValueSpan = makeWithSpan( | ||
| updatedDeploymentVariableValueTracer, | ||
| ); | ||
|
|
||
| export const newDeploymentVariableValue: Handler< | ||
| Event.DeploymentVariableValueCreated | ||
| > = async (event) => { | ||
| const ws = await WorkspaceManager.getOrLoad(event.workspaceId); | ||
| if (ws == null) return; | ||
| await OperationPipeline.update(ws) | ||
| .deploymentVariableValue(event.payload) | ||
| .dispatch(); | ||
| }; | ||
| export const updatedDeploymentVariableValue: Handler<Event.DeploymentVariableValueUpdated> = | ||
| withUpdatedDeploymentVariableValueSpan( | ||
| "updated-deployment-variable-value", | ||
| async (span, event) => { | ||
| span.setAttribute("event.type", event.eventType); | ||
| span.setAttribute( | ||
| "deployment-variable-value.id", | ||
| event.payload.current.id, | ||
| ); | ||
| span.setAttribute( | ||
| "deployment-variable.id", | ||
| event.payload.current.variableId, | ||
| ); | ||
| span.setAttribute("workspace.id", event.workspaceId); | ||
| const ws = await WorkspaceManager.getOrLoad(event.workspaceId); | ||
| if (ws == null) return; | ||
| await OperationPipeline.update(ws) | ||
| .deploymentVariableValue(event.payload.current) | ||
| .dispatch(); | ||
| }, | ||
| ); | ||
|
|
||
| export const updatedDeploymentVariableValue: Handler< | ||
| Event.DeploymentVariableValueUpdated | ||
| > = async (event) => { | ||
| const ws = await WorkspaceManager.getOrLoad(event.workspaceId); | ||
| if (ws == null) return; | ||
| await OperationPipeline.update(ws) | ||
| .deploymentVariableValue(event.payload.current) | ||
| .dispatch(); | ||
| }; | ||
| const deletedDeploymentVariableValueTracer = trace.getTracer( | ||
| "deleted-deployment-variable-value", | ||
| ); | ||
| const withDeletedDeploymentVariableValueSpan = makeWithSpan( | ||
| deletedDeploymentVariableValueTracer, | ||
| ); | ||
|
|
||
| export const deletedDeploymentVariableValue: Handler< | ||
| Event.DeploymentVariableValueDeleted | ||
| > = async (event) => { | ||
| const ws = await WorkspaceManager.getOrLoad(event.workspaceId); | ||
| if (ws == null) return; | ||
| await OperationPipeline.update(ws) | ||
| .deploymentVariableValue(event.payload) | ||
| .dispatch(); | ||
| }; | ||
| export const deletedDeploymentVariableValue: Handler<Event.DeploymentVariableValueDeleted> = | ||
| withDeletedDeploymentVariableValueSpan( | ||
| "deleted-deployment-variable-value", | ||
| async (span, event) => { | ||
| span.setAttribute("event.type", event.eventType); | ||
| span.setAttribute("deployment-variable-value.id", event.payload.id); | ||
| span.setAttribute("deployment-variable.id", event.payload.variableId); | ||
| span.setAttribute("workspace.id", event.workspaceId); | ||
| const ws = await WorkspaceManager.getOrLoad(event.workspaceId); | ||
| if (ws == null) return; | ||
| await OperationPipeline.delete(ws) | ||
| .deploymentVariableValue(event.payload) | ||
| .dispatch(); | ||
| }, | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,48 +1,85 @@ | ||
| import type * as schema from "@ctrlplane/db/schema"; | ||
| import type { Event } from "@ctrlplane/events"; | ||
|
|
||
| import { makeWithSpan, trace } from "@ctrlplane/logger"; | ||
|
|
||
| import type { Handler } from "."; | ||
| import { OperationPipeline } from "../workspace/pipeline.js"; | ||
| import { WorkspaceManager } from "../workspace/workspace.js"; | ||
|
|
||
| const newDeploymentVersionTracer = trace.getTracer("new-deployment-version"); | ||
| const withNewDeploymentVersionSpan = makeWithSpan(newDeploymentVersionTracer); | ||
|
|
||
| const getDeploymentVersionWithDates = ( | ||
| deploymentVersion: schema.DeploymentVersion, | ||
| ) => { | ||
| const createdAt = new Date(deploymentVersion.createdAt); | ||
| return { ...deploymentVersion, createdAt }; | ||
| }; | ||
|
|
||
| export const newDeploymentVersion: Handler< | ||
| Event.DeploymentVersionCreated | ||
| > = async (event) => { | ||
| const ws = await WorkspaceManager.getOrLoad(event.workspaceId); | ||
| if (ws == null) return; | ||
| const deploymentVersion = getDeploymentVersionWithDates(event.payload); | ||
| await OperationPipeline.update(ws) | ||
| .deploymentVersion(deploymentVersion) | ||
| .dispatch(); | ||
| }; | ||
| export const newDeploymentVersion: Handler<Event.DeploymentVersionCreated> = | ||
| withNewDeploymentVersionSpan( | ||
| "new-deployment-version", | ||
| async (span, event) => { | ||
| span.setAttribute("event.type", event.eventType); | ||
| span.setAttribute("deployment-version.id", event.payload.id); | ||
| span.setAttribute("deployment.id", event.payload.deploymentId); | ||
| span.setAttribute("workspace.id", event.workspaceId); | ||
| const ws = await WorkspaceManager.getOrLoad(event.workspaceId); | ||
| if (ws == null) return; | ||
| const deploymentVersion = getDeploymentVersionWithDates(event.payload); | ||
| await OperationPipeline.update(ws) | ||
| .deploymentVersion(deploymentVersion) | ||
| .dispatch(); | ||
| }, | ||
| ); | ||
|
|
||
| const updatedDeploymentVersionTracer = trace.getTracer( | ||
| "updated-deployment-version", | ||
| ); | ||
| const withUpdatedDeploymentVersionSpan = makeWithSpan( | ||
| updatedDeploymentVersionTracer, | ||
| ); | ||
|
|
||
| export const updatedDeploymentVersion: Handler< | ||
| Event.DeploymentVersionUpdated | ||
| > = async (event) => { | ||
| const ws = await WorkspaceManager.getOrLoad(event.workspaceId); | ||
| if (ws == null) return; | ||
| const deploymentVersion = getDeploymentVersionWithDates( | ||
| event.payload.current, | ||
| export const updatedDeploymentVersion: Handler<Event.DeploymentVersionUpdated> = | ||
| withUpdatedDeploymentVersionSpan( | ||
| "updated-deployment-version", | ||
| async (span, event) => { | ||
| span.setAttribute("event.type", event.eventType); | ||
| span.setAttribute("deployment-version.id", event.payload.current.id); | ||
| span.setAttribute("deployment.id", event.payload.current.deploymentId); | ||
| span.setAttribute("workspace.id", event.workspaceId); | ||
| const ws = await WorkspaceManager.getOrLoad(event.workspaceId); | ||
| if (ws == null) return; | ||
| const deploymentVersion = getDeploymentVersionWithDates( | ||
| event.payload.current, | ||
| ); | ||
| await OperationPipeline.update(ws) | ||
| .deploymentVersion(deploymentVersion) | ||
| .dispatch(); | ||
| }, | ||
| ); | ||
| await OperationPipeline.update(ws) | ||
| .deploymentVersion(deploymentVersion) | ||
| .dispatch(); | ||
| }; | ||
|
|
||
| export const deletedDeploymentVersion: Handler< | ||
| Event.DeploymentVersionDeleted | ||
| > = async (event) => { | ||
| const ws = await WorkspaceManager.getOrLoad(event.workspaceId); | ||
| if (ws == null) return; | ||
| const deploymentVersion = getDeploymentVersionWithDates(event.payload); | ||
| await OperationPipeline.delete(ws) | ||
| .deploymentVersion(deploymentVersion) | ||
| .dispatch(); | ||
| }; | ||
| const deletedDeploymentVersionTracer = trace.getTracer( | ||
| "deleted-deployment-version", | ||
| ); | ||
| const withDeletedDeploymentVersionSpan = makeWithSpan( | ||
| deletedDeploymentVersionTracer, | ||
| ); | ||
|
|
||
| export const deletedDeploymentVersion: Handler<Event.DeploymentVersionDeleted> = | ||
| withDeletedDeploymentVersionSpan( | ||
| "deleted-deployment-version", | ||
| async (span, event) => { | ||
| span.setAttribute("event.type", event.eventType); | ||
| span.setAttribute("deployment-version.id", event.payload.id); | ||
| span.setAttribute("deployment.id", event.payload.deploymentId); | ||
| span.setAttribute("workspace.id", event.workspaceId); | ||
| const ws = await WorkspaceManager.getOrLoad(event.workspaceId); | ||
| if (ws == null) return; | ||
| const deploymentVersion = getDeploymentVersionWithDates(event.payload); | ||
| await OperationPipeline.delete(ws) | ||
| .deploymentVersion(deploymentVersion) | ||
| .dispatch(); | ||
| }, | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,31 +1,48 @@ | ||
| import type { Event } from "@ctrlplane/events"; | ||
|
|
||
| import { makeWithSpan, trace } from "@ctrlplane/logger"; | ||
|
|
||
| import type { Handler } from "."; | ||
| import { OperationPipeline } from "../workspace/pipeline.js"; | ||
| import { WorkspaceManager } from "../workspace/workspace.js"; | ||
|
|
||
| export const newDeployment: Handler<Event.DeploymentCreated> = async ( | ||
| event, | ||
| ) => { | ||
| const ws = await WorkspaceManager.getOrLoad(event.workspaceId); | ||
| if (ws == null) return; | ||
| await OperationPipeline.update(ws).deployment(event.payload).dispatch(); | ||
| }; | ||
|
|
||
| export const updatedDeployment: Handler<Event.DeploymentUpdated> = async ( | ||
| event, | ||
| ) => { | ||
| const ws = await WorkspaceManager.getOrLoad(event.workspaceId); | ||
| if (ws == null) return; | ||
| await OperationPipeline.update(ws) | ||
| .deployment(event.payload.current) | ||
| .dispatch(); | ||
| }; | ||
|
|
||
| export const deletedDeployment: Handler<Event.DeploymentDeleted> = async ( | ||
| event, | ||
| ) => { | ||
| const ws = await WorkspaceManager.getOrLoad(event.workspaceId); | ||
| if (ws == null) return; | ||
| await OperationPipeline.delete(ws).deployment(event.payload).dispatch(); | ||
| }; | ||
| const newDeploymentTracer = trace.getTracer("new-deployment"); | ||
| const withNewDeploymentSpan = makeWithSpan(newDeploymentTracer); | ||
|
|
||
| export const newDeployment: Handler<Event.DeploymentCreated> = | ||
| withNewDeploymentSpan("new-deployment", async (span, event) => { | ||
| span.setAttribute("event.type", event.eventType); | ||
| span.setAttribute("deployment.id", event.payload.id); | ||
| span.setAttribute("workspace.id", event.workspaceId); | ||
| const ws = await WorkspaceManager.getOrLoad(event.workspaceId); | ||
| if (ws == null) return; | ||
| await OperationPipeline.update(ws).deployment(event.payload).dispatch(); | ||
| }); | ||
|
|
||
| const updatedDeploymentTracer = trace.getTracer("updated-deployment"); | ||
| const withUpdatedDeploymentSpan = makeWithSpan(updatedDeploymentTracer); | ||
|
|
||
| export const updatedDeployment: Handler<Event.DeploymentUpdated> = | ||
| withUpdatedDeploymentSpan("updated-deployment", async (span, event) => { | ||
| span.setAttribute("event.type", event.eventType); | ||
| span.setAttribute("deployment.id", event.payload.current.id); | ||
| span.setAttribute("workspace.id", event.workspaceId); | ||
| const ws = await WorkspaceManager.getOrLoad(event.workspaceId); | ||
| if (ws == null) return; | ||
| await OperationPipeline.update(ws) | ||
| .deployment(event.payload.current) | ||
| .dispatch(); | ||
| }); | ||
|
|
||
| const deletedDeploymentTracer = trace.getTracer("deleted-deployment"); | ||
| const withDeletedDeploymentSpan = makeWithSpan(deletedDeploymentTracer); | ||
|
|
||
| export const deletedDeployment: Handler<Event.DeploymentDeleted> = | ||
| withDeletedDeploymentSpan("deleted-deployment", async (span, event) => { | ||
| span.setAttribute("event.type", event.eventType); | ||
| span.setAttribute("deployment.id", event.payload.id); | ||
| span.setAttribute("workspace.id", event.workspaceId); | ||
| const ws = await WorkspaceManager.getOrLoad(event.workspaceId); | ||
| if (ws == null) return; | ||
| await OperationPipeline.delete(ws).deployment(event.payload).dispatch(); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Do not silently drop events; fix WorkspaceManager.getOrLoad return bug and set span status on missing workspace.
Right now, the first event for any workspace will be dropped:
WorkspaceManager.getOrLoad()returns the pre-load value instead of the loaded instance. Yourif (ws == null) return;then exits, skipping the pipeline. This is a functional bug. Also, missing workspaces should mark the span as an error, not silently return. (See apps/event-queue/src/workspace/workspace.ts snippet.)Apply this in-file safeguard and error status, and separately fix
getOrLoad:And add the missing import to support
setStatus:Fix
WorkspaceManager.getOrLoadto actually return the loaded instance:Run to confirm other callers aren’t affected and that
getOrLoadis fixed everywhere:Also applies to: 30-34, 45-48
🏁 Script executed:
Length of output: 14398
🏁 Script executed:
Length of output: 1738
Fix getOrLoad return and enforce error spans in event handlers
static async getOrLoad(id: string) {}
In apps/event-queue/src/events/deployments.ts around lines 17-20, the handler
silently returns when WorkspaceManager.getOrLoad yields null which drops the
first event; update WorkspaceManager.getOrLoad in
apps/event-queue/src/workspace/workspace.ts to actually return the loaded
Workspace instance, then in this file replace the simple null-check with the
original fallback + error-span logic: import { SpanStatusCode } from
"@opentelemetry/api", create/obtain the span, if getOrLoad returns null call
span.setStatus({ code: SpanStatusCode.ERROR, message: "workspace not found" })
(or similar) and proceed to use a fallback WorkspaceManager.get before deciding
to stop; apply the same pattern (fallback against WorkspaceManager.get and
span.setStatus on null) to every event handler file under
apps/event-queue/src/events/** that calls getOrLoad so events aren’t silently
dropped.