Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# package:sentry changelog

## 2.0.2

- Add support for user context in Sentry events.

## 2.0.1

- Invert stack frames to be compatible with Sentry's default culprit detection.
Expand Down
47 changes: 29 additions & 18 deletions lib/sentry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,16 @@ class SentryClient {
/// Attached to the event payload.
final String projectId;

/// The user data that will get sent with every logged event
/// Information about the current user.
///
/// Note that a [Event.userContext] that is set on a logged [Event]
/// will override the [User] context set here.
/// This information is sent with every logged event. If the value
/// of this field is updated, all subsequent events will carry the
/// new information.
///
/// see: https://docs.sentry.io/learn/context/#capturing-the-user
/// [Event.userContext] overrides the [User] context set here.
///
/// See also:
/// * https://docs.sentry.io/learn/context/#capturing-the-user
User userContext;

@visibleForTesting
Expand Down Expand Up @@ -178,7 +182,7 @@ class SentryClient {
if (environmentAttributes != null)
mergeAttributes(environmentAttributes.toJson(), into: data);

// merge the user context
// Merge the user context.
if (userContext != null) {
mergeAttributes({'user': userContext.toJson()}, into: data);
}
Expand Down Expand Up @@ -343,7 +347,7 @@ class Event {
/// they must be JSON-serializable.
final Map<String, dynamic> extra;

/// User information that is sent with the logged [Event]
/// Information about the current user.
///
/// The value in this field overrides the user context
/// set in [SentryClient.userContext] for this logged event.
Expand Down Expand Up @@ -420,14 +424,20 @@ class Event {
}
}

/// An interface which describes the authenticated User for a request.
/// You should provide at least either an id (a unique identifier for an
/// authenticated user) or ip_address (their IP address).
/// Describes the current user associated with the application, such as the
/// currently signed in user.
///
/// The user can be specified globally in the [SentryClient.userContext] field,
/// or per event in the [Event.userContext] field.
///
/// You should provide at least either an [id] (a unique identifier for an
/// authenticated user) or [ipAddress] (their IP address).
///
/// Conforms to the User Interface contract for Sentry
/// https://docs.sentry.io/clientdev/interfaces/user/
/// https://docs.sentry.io/clientdev/interfaces/user/.
///
/// The outgoing JSON representation is:
///
/// The outgoing json representation is:
/// ```
/// "user": {
/// "id": "unique_id",
Expand All @@ -438,10 +448,10 @@ class Event {
/// }
/// ```
class User {
/// The unique ID of the user.
/// A unique identifier of the user.
final String id;

/// The username of the user
/// The username of the user.
final String username;

/// The email address of the user.
Expand All @@ -450,16 +460,17 @@ class User {
/// The IP of the user.
final String ipAddress;

/// Any other user context information that may be helpful
/// All other keys are stored as extra information but not
/// specifically processed by sentry.
/// Any other user context information that may be helpful.
///
/// These keys are stored as extra information but not specifically processed
/// by Sentry.
final Map<String, dynamic> extras;

/// At a minimum you must set an [id] or an [ipAddress]
/// At a minimum you must set an [id] or an [ipAddress].
const User({this.id, this.username, this.email, this.ipAddress, this.extras})
: assert(id != null || ipAddress != null);

/// produces a [Map] that can be serialized to JSON
/// Produces a [Map] that can be serialized to JSON.
Map<String, dynamic> toJson() {
return {
"id": id,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/version.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
library version;

/// The SDK version reported to Sentry.io in the submitted events.
const String sdkVersion = '2.0.1';
const String sdkVersion = '2.0.2';

/// The SDK name reported to Sentry.io in the submitted events.
const String sdkName = 'dart';
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: sentry
version: 2.0.1
version: 2.0.2
description: A pure Dart Sentry.io client.
author: Flutter Authors <flutter-dev@googlegroups.com>
homepage: https://github.com/flutter/sentry
Expand Down