|
1 | 1 | import type { Scope } from '@sentry/core';
|
2 | 2 | import { addTracingExtensions, BaseClient, SDK_VERSION, SessionFlusher } from '@sentry/core';
|
3 |
| -import type { Event, EventHint, Severity, SeverityLevel } from '@sentry/types'; |
4 |
| -import { logger, resolvedSyncPromise } from '@sentry/utils'; |
| 3 | +import type { |
| 4 | + CheckIn, |
| 5 | + Event, |
| 6 | + EventHint, |
| 7 | + MonitorConfig, |
| 8 | + SerializedCheckIn, |
| 9 | + Severity, |
| 10 | + SeverityLevel, |
| 11 | +} from '@sentry/types'; |
| 12 | +import { logger, resolvedSyncPromise, uuid4 } from '@sentry/utils'; |
5 | 13 | import * as os from 'os';
|
6 | 14 | import { TextEncoder } from 'util';
|
7 | 15 |
|
| 16 | +import { createCheckInEnvelope } from './checkin'; |
8 | 17 | import { eventFromMessage, eventFromUnknownInput } from './eventbuilder';
|
9 | 18 | import type { NodeClientOptions } from './types';
|
10 | 19 |
|
@@ -138,6 +147,44 @@ export class NodeClient extends BaseClient<NodeClientOptions> {
|
138 | 147 | );
|
139 | 148 | }
|
140 | 149 |
|
| 150 | + /** |
| 151 | + * Create a cron monitor check in and send it to Sentry. |
| 152 | + * |
| 153 | + * @param checkIn An object that describes a check in. |
| 154 | + * @param upsertMonitorConfig An optional object that describes a monitor config. Use this if you want |
| 155 | + * to create a monitor automatically when sending a check in. |
| 156 | + */ |
| 157 | + public captureCheckIn(checkIn: CheckIn, monitorConfig?: MonitorConfig): void { |
| 158 | + if (!this._isEnabled()) { |
| 159 | + __DEBUG_BUILD__ && logger.warn('SDK not enabled, will not capture checkin.'); |
| 160 | + return; |
| 161 | + } |
| 162 | + |
| 163 | + const options = this.getOptions(); |
| 164 | + const { release, environment, tunnel } = options; |
| 165 | + |
| 166 | + const serializedCheckIn: SerializedCheckIn = { |
| 167 | + check_in_id: uuid4(), |
| 168 | + monitor_slug: checkIn.monitorSlug, |
| 169 | + status: checkIn.status, |
| 170 | + duration: checkIn.duration, |
| 171 | + release, |
| 172 | + environment, |
| 173 | + }; |
| 174 | + |
| 175 | + if (monitorConfig) { |
| 176 | + serializedCheckIn.monitor_config = { |
| 177 | + schedule: monitorConfig.schedule, |
| 178 | + checkin_margin: monitorConfig.checkinMargin, |
| 179 | + max_runtime: monitorConfig.maxRuntime, |
| 180 | + timezone: monitorConfig.timezone, |
| 181 | + }; |
| 182 | + } |
| 183 | + |
| 184 | + const envelope = createCheckInEnvelope(serializedCheckIn, this.getSdkMetadata(), tunnel, this.getDsn()); |
| 185 | + void this._sendEnvelope(envelope); |
| 186 | + } |
| 187 | + |
141 | 188 | /**
|
142 | 189 | * @inheritDoc
|
143 | 190 | */
|
|
0 commit comments