Greenbone Vulnerability Management Libraries 22.32.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
14
15#include "gvm_sentry.h"
16
17#include <stdio.h>
18
25int
27{
28#ifdef HAVE_SENTRY
29 return 1;
30#endif /* HAVE_SENTRY */
31 return 0;
32}
33
34#ifdef HAVE_SENTRY
35int global_init_sentry = 0;
36
40static void
41set_init_sentry ()
42{
43 global_init_sentry = 1;
44}
45
49static void
50reset_init_sentry ()
51{
52 global_init_sentry = 0;
53}
54
58static int
59is_sentry_initialized ()
60{
61 return global_init_sentry;
62}
63#endif /* HAVE_SENTRY */
64
73void
74gvm_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
96void
97gvm_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
121void
123{
124#ifdef HAVE_SENTRY
125 if (is_sentry_initialized ())
126 {
127 sentry_close ();
128 reset_init_sentry ();
129 }
130#endif /* HAVE_SENTRY */
131}
void gvm_sentry_init(const char *dsn, const char *release)
Initialize Sentry.
Definition gvm_sentry.c:74
int gvm_has_sentry_support()
Check for sentry support.
Definition gvm_sentry.c:26
void gvm_close_sentry(void)
Shutdown Sentry if it was initialized.
Definition gvm_sentry.c:122
void gvm_sentry_log(const char *message)
Send a message to Sentry server if it was initialized.
Definition gvm_sentry.c:97
Implementation of sentry methods.