Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
9d1e2dd
add metrics option
tustanivsky Apr 22, 2024
c0d9b94
add stubs for metrics emission methods
tustanivsky Apr 23, 2024
105d378
add proper gauge and set values initialization
tustanivsky Apr 24, 2024
8c2aeaa
add measurement units setter
tustanivsky Apr 24, 2024
5cd23ca
add metrics capturing method stub
tustanivsky Apr 24, 2024
c103996
add metrics aggregation
tustanivsky Apr 26, 2024
64bdd3f
fix gauge counting
tustanivsky Apr 29, 2024
d6eb67a
fix bucket filling
tustanivsky Apr 29, 2024
60b489a
add metrics statsd encoding
tustanivsky May 1, 2024
95b59d2
add metrics transport
tustanivsky May 2, 2024
4ba191c
Update changelog
tustanivsky May 7, 2024
6f61d94
Use timestamp in seconds
tustanivsky May 7, 2024
f51fb19
Fix some lint errors
tustanivsky May 7, 2024
b72da6e
Fix more lint errors
tustanivsky May 7, 2024
5fcbf60
Fix more lint errors
tustanivsky May 7, 2024
9bdaed9
Fix more lint errors
tustanivsky May 8, 2024
6433100
Fix lint errors final
tustanivsky May 8, 2024
6234cd4
Fix formatting
tustanivsky May 8, 2024
f243f3c
Fix CI build errors
tustanivsky May 8, 2024
702359b
Fix lint errors
tustanivsky May 8, 2024
fa73188
Fix more CI build errors
tustanivsky May 8, 2024
008eb04
Comment
tustanivsky May 8, 2024
ef75253
Add tag value sanitization util
tustanivsky May 9, 2024
73f62ff
Fix tests
tustanivsky May 9, 2024
03569f7
Fix lint error
tustanivsky May 9, 2024
de4550c
Add statsd string sanitize utils
tustanivsky May 9, 2024
2374bfd
Fix tests
tustanivsky May 9, 2024
5085033
Fix tests
tustanivsky May 9, 2024
aea93a8
Fix tests
tustanivsky May 9, 2024
feffc22
Fix tests
tustanivsky May 9, 2024
a5609aa
Fix tests
tustanivsky May 9, 2024
81fe828
Fix tests
tustanivsky May 9, 2024
d1c6c9b
Fix tests
tustanivsky May 9, 2024
c6c0f47
Fix tests
tustanivsky May 9, 2024
333712f
Add some metrics force flush considerations
tustanivsky May 14, 2024
304691d
Remove empty method
tustanivsky May 14, 2024
d3c7ef0
Add proper force flush logic
tustanivsky May 14, 2024
bdbf5f9
Add periodical metrics flushing
tustanivsky May 14, 2024
3ffc331
Add check if periodical metrics flushing should be stopped
tustanivsky May 14, 2024
c6b2ec7
Fix lint errors
tustanivsky May 14, 2024
0660363
Remove unused method
tustanivsky May 15, 2024
280a859
Add metric creation test
tustanivsky May 21, 2024
da7c86c
Add tests for more metric types
tustanivsky May 21, 2024
09d33e4
Fix tags check
tustanivsky May 21, 2024
ac6798d
Fix lint errors
tustanivsky May 22, 2024
fd11a4d
Move sleep util definition to sentry_sync.h
tustanivsky May 23, 2024
f845bed
Replace camel case with snake case
tustanivsky May 23, 2024
a270272
Fix CI errors
tustanivsky May 23, 2024
8577b25
Rework metrics public API
tustanivsky May 24, 2024
148f528
Fix lint errors
tustanivsky May 24, 2024
21ae71f
Fix CI build errors
tustanivsky May 24, 2024
840dc02
Remove deprecated tests
tustanivsky May 24, 2024
bb5e3e4
Fix methods signature
tustanivsky May 24, 2024
3c96a89
Rename some internal variables
tustanivsky May 27, 2024
dc52dd4
Add extra check for name sanitizer
tustanivsky May 27, 2024
a5329ff
Fix test errors
tustanivsky May 27, 2024
1fd53df
Revert previous changes
tustanivsky May 27, 2024
f80a0b6
Add integration tests stubs
tustanivsky May 27, 2024
c66c281
Merge branch 'master' into feat/metrics-api
tustanivsky May 27, 2024
3f52d11
Remove metrics flush delay for tests
tustanivsky May 27, 2024
70dccea
Merge branch 'feat/metrics-api' of github.com:tustanivsky/sentry-nati…
tustanivsky May 27, 2024
2f5df02
Fix timestamp
tustanivsky May 27, 2024
aa83a16
Fix lint erros
tustanivsky May 27, 2024
81f7cda
Fix lint errors
tustanivsky May 27, 2024
3dccae5
Fix lint errors
tustanivsky May 27, 2024
bf8bbbf
Update src/sentry_metrics.c
tustanivsky May 27, 2024
15148d7
Add convenience macro for metrics test checks
tustanivsky May 27, 2024
37d9abe
Fix copy-paste
tustanivsky May 27, 2024
b56640d
Fix integration test
tustanivsky May 28, 2024
70772d2
Fix timeout
tustanivsky May 28, 2024
8246474
Add basic integration tests
tustanivsky May 28, 2024
108eab8
Fix unused variable during tests
tustanivsky May 29, 2024
ce261dc
Fix tests
tustanivsky May 29, 2024
2d28039
Fix tests
tustanivsky May 29, 2024
86665eb
Fix tests
tustanivsky May 29, 2024
bd1fc8a
Fix lint errors
tustanivsky May 29, 2024
5b9e22b
Fix tests
tustanivsky May 29, 2024
db92384
Add tests cleanup
tustanivsky May 29, 2024
59fd55d
Try fix test
tustanivsky May 29, 2024
d2330d2
Test another fix
tustanivsky May 29, 2024
beb11d2
Try fix leak
tustanivsky May 29, 2024
6aae289
Fix
tustanivsky May 29, 2024
e3ce410
Fix
tustanivsky May 29, 2024
782a210
Update defines
tustanivsky May 29, 2024
ae25e87
Try to fix string sanitize on Android
tustanivsky May 29, 2024
3de7700
Fix include
tustanivsky May 29, 2024
699ca26
Another fix
tustanivsky May 29, 2024
293135d
Fix
tustanivsky May 29, 2024
e490f40
Revert char check
tustanivsky May 29, 2024
b73a37a
Remove metrics enable option
tustanivsky May 30, 2024
8af929d
Add convenience for metrics emission
tustanivsky May 30, 2024
033af5c
Fix macro
tustanivsky May 30, 2024
2f2c057
Refactor
tustanivsky May 30, 2024
3399f78
Replace stringify usages
tustanivsky May 30, 2024
d9ae8ac
Revert "Replace stringify usages"
tustanivsky May 30, 2024
77fcaef
Add metrics check
tustanivsky May 30, 2024
9959deb
Add bucket weight test
tustanivsky May 30, 2024
849ff0f
Add more tests
tustanivsky May 30, 2024
58b8dab
Fix memory leak
tustanivsky May 30, 2024
c9b1bb6
Fix another memory leak
tustanivsky May 30, 2024
5b8a038
Merge remote-tracking branch 'origin/master' into feat/metrics-api
tustanivsky May 30, 2024
d65b93a
Update changelog
tustanivsky May 30, 2024
c52e3c7
ensure that we throw away any non-ASCII chars before the isalnum check
supervacuus Jun 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

**Features**:

- Add Metrics API ([#985](https://github.com/getsentry/sentry-native/pull/985))

## 0.7.5

**Features**:
Expand Down
12 changes: 12 additions & 0 deletions examples/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,18 @@ main(int argc, char **argv)

sentry_capture_user_feedback(user_feedback);
}
if (has_arg(argc, argv, "metrics-emit-increment")) {
sentry_metrics_emit_increment("test-inc", 5.0, "second");
}
if (has_arg(argc, argv, "metrics-emit-distribution")) {
sentry_metrics_emit_distribution("test-dist", 5.0, "second");
}
if (has_arg(argc, argv, "metrics-emit-gauge")) {
sentry_metrics_emit_gauge("test-gauge", 5.0, "second");
}
if (has_arg(argc, argv, "metrics-emit-set")) {
sentry_metrics_emit_set("test-set", 5.0, "second");
}

if (has_arg(argc, argv, "capture-transaction")) {
sentry_transaction_context_t *tx_ctx
Expand Down
92 changes: 92 additions & 0 deletions include/sentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -2058,6 +2058,98 @@ SENTRY_EXPERIMENTAL_API const char *sentry_sdk_name(void);
*/
SENTRY_EXPERIMENTAL_API const char *sentry_sdk_user_agent(void);

/**
* Emits a counter metric.
*
* Counters are one of the more basic types of metrics and can be
* used to count certain event occurrences.
*
* Counter value can only be incremented.
*
* Metrics can be tagged by key-value pairs
* that are set as a variadic parameter.
* For any non-empty tag sequence a terminating `NULL` has to be provided.
*
* See https://develop.sentry.dev/delightful-developer-metrics/
*/
SENTRY_EXPERIMENTAL_API void sentry_metrics_emit_increment_(
const char *key, double value, const char *unit, ...);

/**
* Convenience macro for `sentry_metrics_emit_increment_`.
*/
#define sentry_metrics_emit_increment(key, value, unit, ...) \
sentry_metrics_emit_increment_(key, value, unit, ##__VA_ARGS__, NULL)

/**
* Emits a distribution metric.
*
* Distributions track a list of values over time on which
* aggregations like `p90`, `max`, `min`, `avg` can be performed.
*
* Metrics can be tagged by key-value pairs
* that are set as a variadic parameter.
* For any non-empty tag sequence a terminating `NULL` has to be provided.
*
* See https://develop.sentry.dev/delightful-developer-metrics/
*/
SENTRY_EXPERIMENTAL_API void sentry_metrics_emit_distribution_(
const char *key, double value, const char *unit, ...);

/**
* Convenience macro for `sentry_metrics_emit_distribution_`.
*/
#define sentry_metrics_emit_distribution(key, value, unit, ...) \
sentry_metrics_emit_distribution_(key, value, unit, ##__VA_ARGS__, NULL)

/**
* Emits a gauge metric.
*
* Gauges track a value that can go up and down on which
* aggregations like `max`, `min`, `avg`, `sum` and `count` can be performed.
*
* Gauges can be represented in a more space-efficient way than distributions,
* but they can't be used to get percentiles.
*
* Metrics can be tagged by key-value pairs
* that are set as a variadic parameter.
* For any non-empty tag sequence a terminating `NULL` has to be provided.
*
* See https://develop.sentry.dev/delightful-developer-metrics/
*/
SENTRY_EXPERIMENTAL_API void sentry_metrics_emit_gauge_(
const char *key, double value, const char *unit, ...);

/**
* Convenience macro for `sentry_metrics_emit_gauge_`.
*/
#define sentry_metrics_emit_gauge(key, value, unit, ...) \
sentry_metrics_emit_gauge_(key, value, unit, ##__VA_ARGS__, NULL)

/**
* Emits a set metric.
*
* Sets are useful for looking at unique occurrences and counting
* the unique elements that were added.
*
* Sets track a set of values on which aggregations such as `count_unique`
* can be performed.
*
* Metrics can be tagged by key-value pairs
* that are set as a variadic parameter.
* For any non-empty tag sequence a terminating `NULL` has to be provided.
*
* See https://develop.sentry.dev/delightful-developer-metrics/
*/
SENTRY_EXPERIMENTAL_API void sentry_metrics_emit_set_(
const char *key, int32_t value, const char *unit, ...);

/**
* Convenience macro for `sentry_metrics_emit_set_`.
*/
#define sentry_metrics_emit_set(key, value, unit, ...) \
sentry_metrics_emit_set_(key, value, unit, ##__VA_ARGS__, NULL)

#ifdef __cplusplus
}
#endif
Expand Down
7 changes: 7 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ sentry_target_sources_cwd(sentry
sentry_json.h
sentry_logger.c
sentry_logger.h
sentry_metrics.c
sentry_metrics.h
sentry_options.c
sentry_options.h
sentry_os.c
Expand Down Expand Up @@ -154,3 +156,8 @@ if(SENTRY_INTEGRATION_QT)
integrations/sentry_integration_qt.h
)
endif()

# integration tests
if(SENTRY_INTEGRATIONTEST)
target_compile_definitions(sentry PRIVATE SENTRY_INTEGRATIONTEST)
endif()
33 changes: 33 additions & 0 deletions src/sentry_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "sentry_core.h"
#include "sentry_database.h"
#include "sentry_envelope.h"
#include "sentry_metrics.h"
#include "sentry_options.h"
#include "sentry_path.h"
#include "sentry_random.h"
Expand Down Expand Up @@ -257,6 +258,7 @@ sentry_close(void)
sentry__mutex_unlock(&g_options_lock);

sentry__scope_cleanup();
sentry__metrics_aggregator_cleanup();
sentry_clear_modulecache();

return (int)dumped_envelopes;
Expand Down Expand Up @@ -570,6 +572,24 @@ sentry__prepare_user_feedback(sentry_value_t user_feedback)
return NULL;
}

sentry_envelope_t *
sentry__prepare_metrics(const char *encoded_metrics)
{
sentry_envelope_t *envelope = NULL;

envelope = sentry__envelope_new();
if (!envelope || !sentry__envelope_add_metrics(envelope, encoded_metrics)) {
goto fail;
}

return envelope;

fail:
SENTRY_WARN("dropping metrics");
sentry_envelope_free(envelope);
return NULL;
}

void
sentry_handle_exception(const sentry_ucontext_t *uctx)
{
Expand Down Expand Up @@ -1171,3 +1191,16 @@ sentry_clear_crashed_last_run(void)
sentry__options_unlock();
return success ? 0 : 1;
}

void
sentry__metrics_flush(const char *encoded_metrics)
{
sentry_envelope_t *envelope = NULL;

SENTRY_WITH_OPTIONS (options) {
envelope = sentry__prepare_metrics(encoded_metrics);
if (envelope) {
sentry__capture_envelope(options->transport, envelope);
}
}
}
5 changes: 5 additions & 0 deletions src/sentry_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ sentry_uuid_t sentry__new_event_id(void);
sentry_value_t sentry__ensure_event_id(
sentry_value_t event, sentry_uuid_t *uuid_out);

/**
* Sends statsd-encoded metrics to Sentry
*/
void sentry__metrics_flush(const char *encoded_metrics);

/**
* This will return an owned reference to the global options.
*/
Expand Down
10 changes: 10 additions & 0 deletions src/sentry_envelope.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,16 @@ sentry__envelope_add_user_feedback(
return item;
}

sentry_envelope_item_t *
sentry__envelope_add_metrics(sentry_envelope_t *envelope, const char *metrics)
{
if (!envelope || !metrics) {
return NULL;
}
return sentry__envelope_add_from_buffer(
envelope, metrics, strlen(metrics), "statsd");
}

sentry_envelope_item_t *
sentry__envelope_add_session(
sentry_envelope_t *envelope, const sentry_session_t *session)
Expand Down
6 changes: 6 additions & 0 deletions src/sentry_envelope.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ sentry_envelope_item_t *sentry__envelope_add_transaction(
sentry_envelope_item_t *sentry__envelope_add_user_feedback(
sentry_envelope_t *envelope, sentry_value_t user_feedback);

/**
* Add a encoded metrics data to this envelope.
*/
sentry_envelope_item_t *sentry__envelope_add_metrics(
sentry_envelope_t *envelope, const char *metrics);

/**
* Add a session to this envelope.
*/
Expand Down
Loading