Skip to content

Commit ad4f26d

Browse files
authored
add support for always on profiling to zero config (open-telemetry#2538)
* add support for profiler and memory metrics -Dsplunk.profiler.enabled=true -Dsplunk.profiler.memory.enabled=true -Dsplunk.metrics.enabled=true These are turned off by default, so existing users will not be affected at this time.
1 parent 37e424b commit ad4f26d

20 files changed

+445
-176
lines changed

instrumentation/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ RUN apt-get update && \
77
WORKDIR /libsplunk
88

99
COPY src /libsplunk/src
10-
COPY testdata/instrumentation.conf /libsplunk/testdata/instrumentation.conf
11-
COPY testdata/instrumentation-svcname.conf /libsplunk/testdata/instrumentation-svcname.conf
10+
COPY testdata/instrumentation-default.conf /libsplunk/testdata/instrumentation-default.conf
11+
COPY testdata/instrumentation-options.conf /libsplunk/testdata/instrumentation-options.conf
1212
COPY install/instrumentation.conf /libsplunk/install/instrumentation.conf
1313
COPY Makefile /libsplunk/Makefile

instrumentation/README.md

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ The full path to the auto instrumentation JAR (provided by the installer).
3838
#### `generate_service_name` (optional)
3939

4040
Whether to disable service name generation by the .so. If set to "true" (the default), the .so will attempt to generate
41-
a service name from the Java command arguments. If set to "false", it will not set the service name, leaving it to be
42-
generated by the Java auto-instrumentation library.
43-
41+
a service name from the Java command arguments, or provide a hard-coded service name if `service_name` is set. If set to
42+
"false", it will not set the service name, leaving it to be generated by the Java auto-instrumentation library.
4443
#### `service_name` (optional)
4544

4645
This is an optional override for the service name that would otherwise be generated by the shared object before Java
4746
startup. By default, this line is commented out, but can be uncommented to override the generated name. If this
4847
parameter is set, all instrumented Java applications on this host will have the specified service name (via the
49-
OTEL_SERVICE_NAME environment variable).
48+
OTEL_SERVICE_NAME environment variable). If this override is set and `generate_service_name` is also explicitly set to
49+
`false`, that parameter will win, and the service name will not be set.
5050

5151
### resource_attributes (optional -- typically set by the installer script)
5252

@@ -58,6 +58,35 @@ Java instrumentation jar. Typically, it will be set to something like:
5858

5959
to set the deployment environment for the Splunk backend.
6060

61+
### disable_telemetry (optional)
62+
63+
Set this value to `true` to disable the preloader from sending the `splunk.linux-autoinstr.executions` metric to the
64+
local collector. Default: `false`.
65+
66+
### generate_service_name (optional)
67+
68+
Set this value to `false` to prevent the preloader from setting the `OTEL_SERVICE_NAME` environment variable.
69+
Default: `true`. If this value is `false`, the preloader will not set `OTEL_SERVICE_NAME`, and the soon-to-be running
70+
Java instrumentation library will attempt to set it instead. In the future, this will be the default behavior.
71+
72+
### enable_profiler (optional)
73+
74+
Set this value to `true` to pass `-Dsplunk.profiler.enabled=true` to the starting Java executable, which will enable
75+
[AlwaysOn CPU Profiling](https://docs.splunk.com/Observability/apm/profiling/get-data-in-profiling.html).
76+
Default: `false`.
77+
78+
### enable_profiler_memory (optional)
79+
80+
Set this value to `true` to pass `-Dsplunk.profiler.memory.enabled=true` to the starting Java executable, which will
81+
enable
82+
[AlwaysOn Memory Profiling](https://docs.splunk.com/Observability/apm/profiling/get-data-in-profiling.html).
83+
Default: `false`.
84+
85+
### enable_metrics (optional)
86+
87+
Set this value to `true` to pass `-Dsplunk.metrics.enabled=true` to the starting Java executable, which will enable
88+
[exporting metrics](https://github.com/signalfx/splunk-otel-java/blob/main/docs/metrics.md). Default: `false`.
89+
6190
### Syntax
6291

6392
To add a comment or comment out a line, start it with a `#`.
@@ -79,7 +108,8 @@ This environment variable contains a `-javaagent` flag set to the full path of t
79108

80109
e.g. `JAVA_TOOL_OPTIONS='-javaagent:/usr/lib/splunk-instrumentation/splunk-otel-javaagent.jar'`
81110

82-
This variable is populated by the .so by concatenating the `java_agent_jar` attribute the config to a `-javaagent:` prefix.
111+
This variable is populated by the .so by concatenating the `java_agent_jar` attribute in the config to a `-javaagent:`
112+
prefix, and then appending any additional system properties specified in the configuration file.
83113

84114
#### OTEL_SERVICE_NAME
85115

@@ -93,7 +123,7 @@ _Meta: link to docs about how service name is used and why it's required._
93123
#### OTEL_RESOURCE_ATTRIBUTES
94124

95125
This environment variable contains a list of name-value pairs (separated by `=`s) passed on to the Java instrumentation
96-
jar.
126+
jar.
97127

98128
This variable is set directly from the optional `resource_attributes` attribute in the config.
99129

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
1-
# service_name=default.service
21
java_agent_jar=/usr/lib/splunk-instrumentation/splunk-otel-javaagent.jar
2+
#resource_attributes=deployment.environment=my.environment
3+
#service_name=hardcoded.service
4+
5+
# note: any of the the following lines may be uncommented to override defaults
6+
#disable_telemetry=true
7+
#generate_service_name=false
8+
#enable_profiler=true
9+
#enable_profiler_memory=true
10+
#enable_metrics=true

instrumentation/src/args.c

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ void add_token(struct tokenset *tks, char *token) {
6767
}
6868
}
6969

70-
bool has_token(struct tokenset *tks, char *token) {
70+
int has_token(struct tokenset *tks, char *token) {
7171
// not doing a set implementation at this time since size of array is small
7272
for (int i = 0; i < tks->i; ++i) {
7373
if (strcmp(tks->tokens[i], token) == 0) {
74-
return true;
74+
return 1;
7575
}
7676
}
77-
return false;
77+
return 0;
7878
}
7979

8080
void generate_servicename_from_args(char *dest, char **args, int num_args) {
@@ -154,20 +154,20 @@ void dedupe_hyphenated(char *out, char *str, struct tokenset *pTokenset) {
154154
}
155155
}
156156

157-
bool is_unique_path_element(char *path_element) {
157+
int is_unique_path_element(char *path_element) {
158158
if (strlen(path_element) == 0) {
159-
return false;
159+
return 0;
160160
}
161161

162162
static const char *standard_path_parts[] = {"usr", "local", "bin", "home", "etc", "lib", "opt", ".."};
163163
static const int num_standard_path_parts = 8;
164164
for (int i = 0; i < num_standard_path_parts; ++i) {
165165
const char *part = standard_path_parts[i];
166166
if (strcmp(part, path_element) == 0) {
167-
return false;
167+
return 0;
168168
}
169169
}
170-
return true;
170+
return 1;
171171
}
172172

173173
// removes a .jar suffix/extension from a string if it's long enough
@@ -181,7 +181,7 @@ void truncate_extension(char *str) {
181181
}
182182
}
183183

184-
bool is_legal_java_main_class_with_module(const char *str) {
184+
int is_legal_java_main_class_with_module(const char *str) {
185185
int num_slashes = 0;
186186
int num_dots = 0;
187187
for (int i = 0; str[i] != 0; ++i) {
@@ -193,73 +193,73 @@ bool is_legal_java_main_class_with_module(const char *str) {
193193
}
194194
}
195195
if (num_dots == 0) {
196-
return false;
196+
return 0;
197197
}
198198
if (num_slashes == 0) {
199199
return is_legal_java_main_class(str);
200200
} else if (num_slashes > 1) {
201-
return false;
201+
return 0;
202202
}
203203
char *fq_main_package = strdup(str);
204204
char *module = strsep(&fq_main_package, "/");
205205

206206
if (!is_legal_java_main_class(fq_main_package)) {
207-
return false;
207+
return 0;
208208
}
209209

210210
if (!is_legal_module(module)) {
211-
return false;
211+
return 0;
212212
}
213213

214-
return true;
214+
return 1;
215215
}
216216

217-
bool is_legal_java_main_class(const char *str) {
217+
int is_legal_java_main_class(const char *str) {
218218
if (strstr(str, ".") == NULL) {
219-
return false;
219+
return 0;
220220
}
221221
char *dup = strdup(str);
222222
char *prev;
223-
while (true) {
223+
while (1) {
224224
char *token = strsep(&dup, ".");
225225
if (token == NULL) {
226226
return is_capital_letter(prev[0]);
227227
}
228228
if (!is_legal_java_package_element(token)) {
229-
return false;
229+
return 0;
230230
}
231231
prev = token;
232232
}
233233
}
234234

235-
bool is_capital_letter(const char ch) {
235+
int is_capital_letter(const char ch) {
236236
return ch >= 'A' && ch <= 'Z';
237237
}
238238

239-
bool is_legal_module(char *module) {
239+
int is_legal_module(char *module) {
240240
char *dup = strdup(module);
241241
char *token;
242242
while ((token = strsep(&dup, ".")) != NULL) {
243243
if (!is_legal_java_package_element(token)) {
244-
return false;
244+
return 0;
245245
}
246246
}
247-
return true;
247+
return 1;
248248
}
249249

250250
// tests if the parts between the dots in e.g. some.package.MyMain are legal
251-
bool is_legal_java_package_element(const char *str) {
251+
int is_legal_java_package_element(const char *str) {
252252
for (int i = 0;; ++i) {
253253
char ch = str[i];
254254
if (ch == 0) {
255255
break;
256256
}
257257
if (i == 0 && ch >= '0' && ch <= '9') {
258-
return false;
258+
return 0;
259259
}
260260
if (ch < '0' || (ch > '9' && ch < 'A') || (ch > 'Z' && ch < '_') || ch == '`' || ch > 'z') {
261-
return false;
261+
return 0;
262262
}
263263
}
264-
return true;
264+
return 1;
265265
}

instrumentation/src/args.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ void init_tokenset(struct tokenset *tks);
1515

1616
void free_tokenset(struct tokenset *tks);
1717

18-
bool has_token(struct tokenset *tks, char *token);
18+
int has_token(struct tokenset *tks, char *token);
1919

2020
void add_token(struct tokenset *tks, char *token);
2121

@@ -25,23 +25,23 @@ void free_cmdline_args(char **args, int num_args);
2525

2626
void generate_servicename_from_args(char *dest, char **args, int num_args);
2727

28-
bool is_legal_java_main_class(const char *str);
28+
int is_legal_java_main_class(const char *str);
2929

30-
bool is_capital_letter(char ch);
30+
int is_capital_letter(char ch);
3131

32-
bool is_legal_java_main_class_with_module(const char *str);
32+
int is_legal_java_main_class_with_module(const char *str);
3333

34-
bool is_legal_module(char *module);
34+
int is_legal_module(char *module);
3535

36-
bool is_legal_java_package_element(const char *str);
36+
int is_legal_java_package_element(const char *str);
3737

3838
void transform_multi_jars(char *dest, char *arg, struct tokenset *tks);
3939

4040
void transform_jar_path_elements(char *out, char *path);
4141

4242
void dedupe_hyphenated(char *out, char *str, struct tokenset *pTokenset);
4343

44-
bool is_unique_path_element(char *path_element);
44+
int is_unique_path_element(char *path_element);
4545

4646
void truncate_extension(char *str);
4747

instrumentation/src/cmdline_reader.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ void cmdline_reader_open(cmdline_reader cr) {
2222
cr->f = fopen(fname, "r");
2323
}
2424

25-
bool cmdline_reader_is_eof(cmdline_reader cr) {
25+
int cmdline_reader_is_eof(cmdline_reader cr) {
2626
return feof(cr->f) != 0;
2727
}
2828

instrumentation/src/cmdline_reader.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
#ifndef INSTRUMENTATION_CMDLINE_READER_H
22
#define INSTRUMENTATION_CMDLINE_READER_H
33

4-
#include <stdbool.h>
5-
64
typedef struct cmdline_reader_impl *cmdline_reader;
75
cmdline_reader new_cmdline_reader();
86
cmdline_reader new_test_cmdline_reader(char *cmdline, int len);
97
void cmdline_reader_open(cmdline_reader cr);
10-
bool cmdline_reader_is_eof(cmdline_reader cr);
8+
int cmdline_reader_is_eof(cmdline_reader cr);
119
char cmdline_reader_get_char(cmdline_reader cr);
1210
void cmdline_reader_close(cmdline_reader cr);
1311

instrumentation/src/cmdline_reader_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ cmdline_reader new_test_cmdline_reader(char *cmdline, int size) {
3131
void cmdline_reader_open(cmdline_reader cr) {
3232
}
3333

34-
bool cmdline_reader_is_eof(cmdline_reader cr) {
34+
int cmdline_reader_is_eof(cmdline_reader cr) {
3535
return cr->i >= cr->size;
3636
}
3737

0 commit comments

Comments
 (0)