Skip to content

Commit 725b062

Browse files
jpnurmiclaude
andcommitted
fix(metrics): scope attributes
Global attributes set via sentry_set_attribute() were not being merged into metrics. Now scope attributes are merged with user attributes having priority on conflicts. Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 8b0c9c6 commit 725b062

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/sentry_metrics.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "sentry_core.h"
44
#include "sentry_envelope.h"
55
#include "sentry_options.h"
6+
#include "sentry_scope.h"
67
#include "sentry_utils.h"
78
#include "sentry_value.h"
89

@@ -63,14 +64,14 @@ construct_metric(sentry_metric_type_t type, const char *name,
6364
sentry_value_set_by_key(metric, "unit", sentry_value_new_string(unit));
6465
}
6566

66-
sentry_value_t attributes = sentry_value_new_object();
67-
sentry__apply_attributes(metric, attributes);
68-
if (sentry_value_get_type(user_attributes) == SENTRY_VALUE_TYPE_OBJECT
69-
&& sentry_value_get_length(user_attributes) > 0) {
70-
sentry__value_merge_objects(attributes, user_attributes);
71-
}
67+
sentry_value_t attributes
68+
= sentry_value_get_type(user_attributes) == SENTRY_VALUE_TYPE_OBJECT
69+
? sentry__value_clone(user_attributes)
70+
: sentry_value_new_object();
7271
sentry_value_decref(user_attributes);
7372

73+
sentry__apply_attributes(metric, attributes);
74+
7475
if (sentry_value_get_length(attributes) > 0) {
7576
sentry_value_set_by_key(metric, "attributes", attributes);
7677
} else {

0 commit comments

Comments
 (0)