Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

JoshuaMoelans
Copy link
Member

@JoshuaMoelans JoshuaMoelans commented May 6, 2025

Came up in discussion of #1225 ; when creating a user object, it's not immediately obvious which fields are expected and how they should be cased. Hence we add a sentry_value_new_user(id, username, email, ip_address) function that constructs the user object with the correct keys (as defined in the develop docs).

The function should be used as follows:

sentry_value_t user = sentry_value_new_user(NULL, "John Doe", "[email protected]", NULL);
sentry_value_set_by_key(user, "custom_key", sentry_value_new_string("custom_value"));
sentry_set_user(user);

ToDo:

Copy link

github-actions bot commented May 6, 2025

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 80e6839

@JoshuaMoelans JoshuaMoelans changed the title feat: add user object creation helper function feat: add sentry_value_new_user May 6, 2025
@JoshuaMoelans JoshuaMoelans marked this pull request as ready for review May 6, 2025 15:00
@JoshuaMoelans JoshuaMoelans requested a review from Copilot May 7, 2025 10:21
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new function, sentry_value_new_user, to construct a user object with the correct key casing as defined in the documentation. Key changes include implementation of the user object creation functions in src/sentry_value.c, test case additions in tests/unit/test_value.c, and updates in related examples and documentation files.

Reviewed Changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/unit/test_value.c Added tests to validate new user object creation, including edge cases.
tests/assertions.py Updated expected user id type from integer to string.
src/sentry_value.c Implemented sentry_value_new_user and helper function sentry_value_new_user_n.
include/sentry.h Added API prototypes and documentation for the new user functions.
examples/example.c Updated usage example to reflect string type for user id.
CHANGELOG.md Updated changelog to document the new feature.
Files not reviewed (1)
  • tests/unit/tests.inc: Language not supported

TEST_CHECK(sentry_value_is_null(user_null));
sentry_value_decref(user_null);

sentry_value_t user_empty_str = sentry_value_new_user("", "", "", "");
Copy link
Preview

Copilot AI May 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider adding an inline comment explaining that providing empty strings as parameters should result in a null user, to clarify the expected behavior in this test.

Suggested change
sentry_value_t user_empty_str = sentry_value_new_user("", "", "", "");
sentry_value_t user_empty_str = sentry_value_new_user("", "", "", "");
// Providing empty strings as parameters should result in a null user.

Copilot uses AI. Check for mistakes.

if (ip_address && ip_address_len) {
sentry_value_set_by_key(
rv, "ip_address", sentry_value_new_string(ip_address));
}
Copy link
Preview

Copilot AI May 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] It would be beneficial to add a comment describing the criteria under which the user object is considered invalid (i.e. when all parameters are empty or null), clarifying why the function returns null.

Suggested change
}
}
// If none of the provided parameters (id, username, email, ip_address) are valid
// (i.e., all are null or empty), the user object is considered invalid.
// In this case, a warning is logged, and a null value is returned.

Copilot uses AI. Check for mistakes.

@supervacuus
Copy link
Collaborator

The only thing left is updating the docs to eliminate manual key-setting.

@JoshuaMoelans JoshuaMoelans merged commit 8755115 into master May 7, 2025
33 checks passed
@JoshuaMoelans JoshuaMoelans deleted the joshua/feat/user_creation branch May 7, 2025 15:40
JoshuaMoelans added a commit to getsentry/sentry-docs that referenced this pull request May 7, 2025
…output (#13624)

<!-- Use this checklist to make sure your PR is ready for merge. You may
delete any sections you don't need. -->

Relevant vercel preview pages
-
https://sentry-docs-plsrr24j2.sentry.dev/platforms/native/enriching-events/scopes/#configuring-the-scope
-
https://sentry-docs-plsrr24j2.sentry.dev//platforms/native/enriching-events/identify-user/
-
https://sentry-docs-plsrr24j2.sentry.dev/platforms/native/data-management/sensitive-data/#examples

## DESCRIBE YOUR PR
Related to the change in
getsentry/sentry-native#1228

From now on, we provide the `sentry_value_new_user(id, username, email,
ip_address)` function that fills out the correct keys. This should
reduce user error & confusion with what keys are processed by Sentry
(see the [original
issue](getsentry/sentry-native#1225) the
function was added for).

## IS YOUR CHANGE URGENT?  

Help us prioritize incoming PRs by letting us know when the change needs
to go live.
- [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE -->
- [ ] Other deadline: <!-- ENTER DATE HERE -->
- [x] None: Not urgent, can wait up to 1 week+

## SLA

- Teamwork makes the dream work, so please add a reviewer to your PRs.
- Please give the docs team up to 1 week to review your PR unless you've
added an urgent due date to it.
Thanks in advance for your help!

## PRE-MERGE CHECKLIST

*Make sure you've checked the following before merging your changes:*

- [x] Checked Vercel preview for correctness, including links
- [ ] PR was reviewed and approved by any necessary SMEs (subject matter
experts)
- [ ] PR was reviewed and approved by a member of the [Sentry docs
team](https://github.com/orgs/getsentry/teams/docs)

---------

Co-authored-by: Mischan Toosarani-Hausberger <[email protected]>
bitsandfoxes pushed a commit to getsentry/sentry-docs that referenced this pull request Jul 3, 2025
…output (#13624)

<!-- Use this checklist to make sure your PR is ready for merge. You may
delete any sections you don't need. -->

Relevant vercel preview pages
-
https://sentry-docs-plsrr24j2.sentry.dev/platforms/native/enriching-events/scopes/#configuring-the-scope
-
https://sentry-docs-plsrr24j2.sentry.dev//platforms/native/enriching-events/identify-user/
-
https://sentry-docs-plsrr24j2.sentry.dev/platforms/native/data-management/sensitive-data/#examples

## DESCRIBE YOUR PR
Related to the change in
getsentry/sentry-native#1228

From now on, we provide the `sentry_value_new_user(id, username, email,
ip_address)` function that fills out the correct keys. This should
reduce user error & confusion with what keys are processed by Sentry
(see the [original
issue](getsentry/sentry-native#1225) the
function was added for).

## IS YOUR CHANGE URGENT?  

Help us prioritize incoming PRs by letting us know when the change needs
to go live.
- [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE -->
- [ ] Other deadline: <!-- ENTER DATE HERE -->
- [x] None: Not urgent, can wait up to 1 week+

## SLA

- Teamwork makes the dream work, so please add a reviewer to your PRs.
- Please give the docs team up to 1 week to review your PR unless you've
added an urgent due date to it.
Thanks in advance for your help!

## PRE-MERGE CHECKLIST

*Make sure you've checked the following before merging your changes:*

- [x] Checked Vercel preview for correctness, including links
- [ ] PR was reviewed and approved by any necessary SMEs (subject matter
experts)
- [ ] PR was reviewed and approved by a member of the [Sentry docs
team](https://github.com/orgs/getsentry/teams/docs)

---------

Co-authored-by: Mischan Toosarani-Hausberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants