Greenbone Vulnerability Management Libraries  22.8.0
gvm_sentry.c
Go to the documentation of this file.
1 /* SPDX-FileCopyrightText: 2017-2023 Greenbone AG
2  *
3  * SPDX-License-Identifier: GPL-2.0-or-later
4  */
5 
15 #include "gvm_sentry.h"
16 
17 #include <stdio.h>
18 
25 int
27 {
28 #ifdef HAVE_SENTRY
29  return 1;
30 #endif /* HAVE_SENTRY */
31  return 0;
32 }
33 
34 #ifdef HAVE_SENTRY
35 int global_init_sentry = 0;
36 
40 static void
41 set_init_sentry ()
42 {
43  global_init_sentry = 1;
44 }
45 
49 static void
50 reset_init_sentry ()
51 {
52  global_init_sentry = 0;
53 }
54 
58 static int
59 is_sentry_initialized ()
60 {
61  return global_init_sentry;
62 }
63 #endif /* HAVE_SENTRY */
64 
73 void
74 gvm_sentry_init (const char *dsn, const char *release)
75 {
76 #ifdef HAVE_SENTRY
77  sentry_options_t *options = sentry_options_new ();
78  sentry_options_set_dsn (options, dsn);
79  sentry_options_set_release (options, release);
80  sentry_options_set_sample_rate (options, 1.0);
81  sentry_init (options);
82  set_init_sentry ();
83 #else
84  (void) dsn;
85  (void) release;
86 #endif /* HAVE_SENTRY */
87 }
88 
96 void
97 gvm_sentry_log (const char *message)
98 {
99 #ifdef HAVE_SENTRY
100  if (is_sentry_initialized ())
101  {
102  sentry_capture_event (sentry_value_new_message_event (
103  /* level */ SENTRY_LEVEL_INFO,
104  /* logger */ "custom",
105  /* message */ message));
106  }
107 #else
108  (void) message;
109 #endif /* HAVE_SENTRY */
110 }
111 
121 void
123 {
124 #ifdef HAVE_SENTRY
125  if (is_sentry_initialized ())
126  {
127  sentry_close ();
128  reset_init_sentry ();
129  }
130 #endif /* HAVE_SENTRY */
131 }
gvm_has_sentry_support
int gvm_has_sentry_support()
Check for sentry support.
Definition: gvm_sentry.c:26
gvm_sentry_init
void gvm_sentry_init(const char *dsn, const char *release)
Initialize Sentry.
Definition: gvm_sentry.c:74
gvm_sentry.h
Implementation of sentry methods.
gvm_sentry_log
void gvm_sentry_log(const char *message)
Send a message to Sentry server if it was initialized.
Definition: gvm_sentry.c:97
gvm_close_sentry
void gvm_close_sentry(void)
Shutdown Sentry if it was initialized.
Definition: gvm_sentry.c:122