Operational

DocsGithub Open app

Operational

Github Articles Pitch Usecases Playground API

Contents

Start hereAPI DocsIntroductionSend your first eventEvent parametersStructured EventsActionsContextsCategoriesError handlingManualIntroductionBasicsConventionsSetupTest modeNotificationsPWASelf hostingIntroductionInstall locallyInstall on VPSInstall on RenderInstall via DockerInstall via Docker and CoolifyOnboardingSetup .envIntegrationsBest practicesOtherVisionRoadmapContributing

Sending contextual events

Contextual events are events-in-events. Think of them as specific group of events that chained together. You can use this to visualized cron jobs, complex functions, workflows, etc.

Here’s a simple example:

// first event
let e = {
  name: "cron job started",
  avatar: "🤖",
  contextId : "1_cron_job", // contextId needs to be common for all contextual events
  contextStart : true // context start is only true for the first contextual event
};

await ops.events.ingest(e);

// later on
e = {
  name: "processing",
  contextId : "1_cron_job",
  content : "343543 job failed"
};

await ops.events.ingest(e);

// some time later
e = {
  name: "processing",
  contextId : "1_cron_job",
  contextId : "183542 job passed"
};

await ops.events.ingest(e);

Copy

To start with contextual events, you need to make contextStart : true for the first event in the context and supply a contextId that is common for all contextual events in the chain. Note that you only need to mark the first event in the chain with contextStart:true.

What is the contextId?

Imagine contextual events as part of a chain. To join events together in this chain, you need to have a common id. contextId is exactly that.

However, you need a id that is also sufficiently unique for a chain of events that happen over various time periods and in seperate parts of your codebase.

For instance, if you’re tracking user signup flow, you might want to have "user_signup_" + userId as the contextId. This will generate a context of user_signup events for that specific user only.

Here’s an example.

const e = {
  name : 'Cron job started',
  contextId : 'cronjob_1',
  contextStart : true,
  avatar: "🤖",
}
Copy

Then further down your code base, add this in:

const e = {
  name : 'Cron job: processing job',
  contextId : 'cronjob_1',
}
Copy

And finally:

const e = {
  name : 'Cron job: processing finished',
  contextId : 'cronjob_1',
  type : "rows",
  content : [
    {
      label : 'Successful jobs',
      content : 10
    },
    {
      label : 'Failed jobs',
      content : 3
    }
  ]
}
Copy

Putting it all together, these events will look like this:

ActionsCategories

Operational

Event tracker for your product.

PrivacyTerms
About the product
  • Playground
  • API
  • Pitch
  • Wordpress plugin
  • Bubble plugin
Related to the product
  • VS Logsnag
  • Open Source
  • Articles
Useful articles for your business
  • Force post: The Payment Hack that lets Merchants charge you without approval
  • 6 Best practices for early stage B2B SaaS customer support
  • Setup event notifications for your SaaS
  • How to get high quality users for your B2B SaaS business?