Skip to content

Commit aab2db6

Browse files
committed
add tagCallback option
1 parent ebee16c commit aab2db6

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/SentryTarget.php

+20
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ class SentryTarget extends Target
4747
* @var callable Callback function that can modify extra's array
4848
*/
4949
public $extraCallback;
50+
/**
51+
* @var callable Callback function that can add tags
52+
*/
53+
public $tagCallback;
5054

5155
/**
5256
* @inheritDoc
@@ -159,6 +163,7 @@ public function export()
159163

160164
$scope->setUser($data['userData']);
161165
$scope->setContext('yii2-sentry', $data['context']);
166+
$data = $this->runTagCallback($data);
162167
foreach ($data['tags'] as $key => $value) {
163168
if ($value) {
164169
$scope->setTag($key, $value);
@@ -197,6 +202,21 @@ public function runExtraCallback($text, $data)
197202
return $data;
198203
}
199204

205+
/**
206+
* Calls the tag callback if it exists
207+
*
208+
* @param array $data
209+
*
210+
* @return array
211+
*/
212+
public function runTagCallback($data)
213+
{
214+
if (is_callable($this->tagCallback)) {
215+
$data['tags'] = call_user_func($this->tagCallback, $data['tags'] ?? []);
216+
}
217+
return $data;
218+
}
219+
200220
/**
201221
* Returns the text display of the specified level for the Sentry.
202222
*

0 commit comments

Comments
 (0)