Skip to content

Commit 2b88be4

Browse files
committed
[opentelemetry] added proc_profiling modparam to enable PROC profiling too
1 parent cc32efb commit 2b88be4

2 files changed

Lines changed: 31 additions & 9 deletions

File tree

modules/opentelemetry/doc/opentelemetry_admin.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,27 @@ modparam("opentelemetry", "enable", 1)
9696
</example>
9797
</section>
9898

99+
<section id="param_proc_profiling" xreflabel="proc_profiling">
100+
<title><varname>proc_profiling</varname> (integer)</title>
101+
<para>
102+
If enabled, the module will also profile/trace the &osips; processes,
103+
not only the script.
104+
</para>
105+
<para>
106+
<emphasis>
107+
Default value is <quote>0 (disabled)</quote>.
108+
</emphasis>
109+
</para>
110+
<example>
111+
<title>Set <varname>proc_profiling</varname> parameter</title>
112+
<programlisting format="linespecific">
113+
...
114+
modparam("opentelemetry", "proc_profiling", 1)
115+
...
116+
</programlisting>
117+
</example>
118+
</section>
119+
99120
<section id="param_log_level" xreflabel="log_level">
100121
<title><varname>log_level</varname> (integer)</title>
101122
<para>

modules/opentelemetry/opentelemetry.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ extern "C" {
7777
#endif
7878

7979
static int otel_enabled_cfg = 0;
80+
static int enable_proc = 0;
8081
static int *otel_enabled = NULL;
8182
static int otel_log_level = L_DBG;
8283
static int otel_use_batch = 1;
@@ -99,7 +100,6 @@ static __thread int otel_log_in_cb;
99100

100101
static __thread profiling_ctx_t otel_parent_ctx;
101102
static __thread int otel_parent_ctx_set;
102-
static int otel_trace_registered;
103103
static int otel_log_consumer_registered;
104104

105105
static opentelemetry::nostd::shared_ptr<oteltrace::Tracer> otel_tracer;
@@ -719,6 +719,7 @@ profiling_handlers_t otel_trace_handlers = {
719719

720720
static const param_export_t params[] = {
721721
{ "enable", INT_PARAM, &otel_enabled_cfg },
722+
{ "proc_profiling", INT_PARAM, &enable_proc},
722723
{ "log_level", INT_PARAM, &otel_log_level },
723724
{ "use_batch", INT_PARAM, &otel_use_batch },
724725
{ "service_name", STR_PARAM, &otel_service_name.s },
@@ -768,6 +769,14 @@ static int mod_init(void)
768769
*otel_enabled = otel_enabled_cfg;
769770
}
770771

772+
if (enable_proc)
773+
otel_trace_handlers.accepted_data_types |= PROFILING_DATA_TYPE_PROC;
774+
775+
if (register_profiling_handler(&otel_trace_handlers) != 0) {
776+
LM_ERR("failed to register profiling hooks\n");
777+
return -1;
778+
}
779+
771780
if (!otel_is_enabled()) {
772781
LM_INFO("opentelemetry module disabled\n");
773782
}
@@ -790,14 +799,6 @@ static int child_init(int rank)
790799
otel_log_in_cb = 0;
791800
otel_parent_ctx_clear();
792801

793-
if (!otel_trace_registered) {
794-
if (register_profiling_handler(&otel_trace_handlers) != 0) {
795-
LM_ERR("failed to register profiling hooks\n");
796-
return -1;
797-
}
798-
otel_trace_registered = 1;
799-
}
800-
801802
if (!otel_log_consumer_registered) {
802803
if (register_log_consumer(OTEL_CONSUMER_NAME, otel_log_consumer,
803804
otel_log_level, 0) != 0) {

0 commit comments

Comments
 (0)