1
1
import { getCurrentHub , Hub , Scope } from '@sentry/hub' ;
2
- import { Breadcrumb , Event , Severity } from '@sentry/types' ;
2
+ import { Breadcrumb , Event , Severity , User } from '@sentry/types' ;
3
3
4
4
/**
5
5
* This calls a function on the current hub.
@@ -64,6 +64,14 @@ export function captureEvent(event: Event): string {
64
64
return callOnHub ( 'captureEvent' , event ) ;
65
65
}
66
66
67
+ /**
68
+ * Callback to set context information onto the scope.
69
+ * @param callback Callback function that receives Scope.
70
+ */
71
+ export function configureScope ( callback : ( scope : Scope ) => void ) : void {
72
+ callOnHub < void > ( 'configureScope' , callback ) ;
73
+ }
74
+
67
75
/**
68
76
* Records a new breadcrumb which will be attached to future events.
69
77
*
@@ -77,11 +85,56 @@ export function addBreadcrumb(breadcrumb: Breadcrumb): void {
77
85
}
78
86
79
87
/**
80
- * Callback to set context information onto the scope.
81
- * @param callback Callback function that receives Scope.
88
+ * Sets context data with the given name.
89
+ * @param name of the context
90
+ * @param context Any kind of data. This data will be normailzed.
82
91
*/
83
- export function configureScope ( callback : ( scope : Scope ) => void ) : void {
84
- callOnHub < void > ( 'configureScope' , callback ) ;
92
+ export function setContext ( name : string , context : { [ key : string ] : any } | null ) : void {
93
+ callOnHub < void > ( 'setContext' , name , context ) ;
94
+ }
95
+
96
+ /**
97
+ * Set an object that will be merged sent as extra data with the event.
98
+ * @param extras Extras object to merge into current context.
99
+ */
100
+ export function setExtras ( extras : { [ key : string ] : any } ) : void {
101
+ callOnHub < void > ( 'setExtras' , extras ) ;
102
+ }
103
+
104
+ /**
105
+ * Set an object that will be merged sent as tags data with the event.
106
+ * @param tags Tags context object to merge into current context.
107
+ */
108
+ export function setTags ( tags : { [ key : string ] : string } ) : void {
109
+ callOnHub < void > ( 'setTags' , tags ) ;
110
+ }
111
+
112
+ /**
113
+ * Set key:value that will be sent as extra data with the event.
114
+ * @param key String of extra
115
+ * @param extra Any kind of data. This data will be normailzed.
116
+ */
117
+
118
+ export function setExtra ( key : string , extra : any ) : void {
119
+ callOnHub < void > ( 'setExtra' , key , extra ) ;
120
+ }
121
+
122
+ /**
123
+ * Set key:value that will be sent as tags data with the event.
124
+ * @param key String key of tag
125
+ * @param value String value of tag
126
+ */
127
+ export function setTag ( key : string , value : string ) : void {
128
+ callOnHub < void > ( 'setTag' , key , value ) ;
129
+ }
130
+
131
+ /**
132
+ * Updates user context information for future events.
133
+ *
134
+ * @param user User context object to be set in the current context. Pass `null` to unset the user.
135
+ */
136
+ export function setUser ( user : User | null ) : void {
137
+ callOnHub < void > ( 'setUser' , user ) ;
85
138
}
86
139
87
140
/**
0 commit comments