about summary refs log tree commit diff
path: root/src/logger/types.ts
blob: 4743e866c49dc0a8c2331ddc657820509a3c46f8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/**
 * DO NOT IMPORT THIS DIRECTLY
 *
 * Logger contexts, defined here and used via `Logger.Context.*` static prop.
 */
export enum LogContext {
  Default = 'logger',
  Session = 'session',
  Notifications = 'notifications',
  ConversationAgent = 'conversation-agent',
  DMsAgent = 'dms-agent',
  ReportDialog = 'report-dialog',
  FeedFeedback = 'feed-feedback',
  PostSource = 'post-source',
  AgeAssurance = 'age-assurance',

  /**
   * METRIC IS FOR INTERNAL USE ONLY, don't create any other loggers using this
   * context
   */
  Metric = 'metric',
}

export enum LogLevel {
  Debug = 'debug',
  Info = 'info',
  Log = 'log',
  Warn = 'warn',
  Error = 'error',
}

export type Transport = (
  level: LogLevel,
  context: LogContext | undefined,
  message: string | Error,
  metadata: Metadata,
  timestamp: number,
) => void

/**
 * A union of some of Sentry's breadcrumb properties as well as Sentry's
 * `captureException` parameter, `CaptureContext`.
 */
export type Metadata = {
  /**
   * Reserved for appending `LogContext` in logging payloads
   */
  __context__?: undefined

  /**
   * Applied as Sentry breadcrumb types. Defaults to `default`.
   *
   * @see https://develop.sentry.dev/sdk/event-payloads/breadcrumbs/#breadcrumb-types
   */
  type?:
    | 'default'
    | 'debug'
    | 'error'
    | 'navigation'
    | 'http'
    | 'info'
    | 'query'
    | 'transaction'
    | 'ui'
    | 'user'

  /**
   * Passed through to `Sentry.captureException`
   *
   * @see https://github.com/getsentry/sentry-javascript/blob/903addf9a1a1534a6cb2ba3143654b918a86f6dd/packages/types/src/misc.ts#L65
   */
  tags?: {
    [key: string]: number | string | boolean | null | undefined
  }

  /**
   * Any additional data, passed through to Sentry as `extra` param on
   * exceptions, or the `data` param on breadcrumbs.
   */
  [key: string]: Serializable | Error | unknown
}

export type Serializable =
  | string
  | number
  | boolean
  | null
  | undefined
  | Serializable[]
  | {
      [key: string]: Serializable
    }