Skip to content

Commit 2c50eb4

Browse files
Fix Symfony callback syntax (#4658)
* Fix Symfony callback syntax * Update src/platforms/php/guides/symfony/configuration/symfony-options.mdx Co-authored-by: Isabel <[email protected]> Co-authored-by: Isabel <[email protected]>
1 parent 7f94e03 commit 2c50eb4

File tree

8 files changed

+108
-30
lines changed

8 files changed

+108
-30
lines changed

src/includes/configuration/before-send-fingerprint/php.symfony.mdx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
```yaml {filename:config/packages/sentry.yaml}
22
sentry:
33
options:
4-
before_send: 'sentry_before_send'
4+
before_send: 'sentry.callback.before_send'
55

66
services:
7-
sentry_before_send:
8-
factory: ['@\App\Service\Sentry', 'getBeforeSend']
7+
sentry.callback.before_send:
8+
class: 'App\Service\Sentry'
9+
factory: [ '@App\Service\Sentry', 'getBeforeSend' ]
910
```
1011
1112
The service needed for the `before_send` option can be implemented as follows:
@@ -29,3 +30,9 @@ class Sentry
2930
}
3031
}
3132
```
33+
34+
<Note>
35+
36+
Learn more in [Callables in Symfony Options](/platforms/php/guides/symfony/configuration/symfony-options/#callables).
37+
38+
</Note>

src/includes/configuration/before-send-hint/php.symfony.mdx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
```yaml {filename:config/packages/sentry.yaml}
22
sentry:
33
options:
4-
before_send: 'sentry_before_send'
4+
before_send: 'sentry.callback.before_send'
55

66
services:
7-
sentry_before_send:
8-
factory: ['@\App\Service\Sentry', 'getBeforeSend']
7+
sentry.callback.before_send:
8+
class: 'App\Service\Sentry'
9+
factory: [ '@App\Service\Sentry', 'getBeforeSend' ]
910
```
1011
1112
The service needed for the `before_send` option can be implemented as follows:
@@ -30,3 +31,9 @@ class Sentry
3031
}
3132
}
3233
```
34+
35+
<Note>
36+
37+
Learn more in [Callables in Symfony Options](/platforms/php/guides/symfony/configuration/symfony-options/#callables).
38+
39+
</Note>

src/includes/configuration/before-send/php.symfony.mdx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ In the Symfony config, a service can be used to modify the event or return a com
33
```yaml {filename:config/packages/sentry.yaml}
44
sentry:
55
options:
6-
before_send: 'sentry_before_send'
6+
before_send: 'sentry.callback.before_send'
77

88
services:
9-
sentry_before_send:
10-
factory: ['@\App\Service\Sentry', 'getBeforeSend']
9+
sentry.callback.before_send:
10+
class: 'App\Service\Sentry'
11+
factory: [ '@App\Service\Sentry', 'getBeforeSend' ]
1112
```
1213
1314
The service needed for the `before_send` option can be implemented as follows:
@@ -27,3 +28,9 @@ class Sentry
2728
}
2829
}
2930
```
31+
32+
<Note>
33+
34+
Learn more in [Callables in Symfony Options](/platforms/php/guides/symfony/configuration/symfony-options/#callables).
35+
36+
</Note>

src/includes/enriching-events/breadcrumbs/before-breadcrumb/php.symfony.mdx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
```yaml {filename:config/packages/sentry.yaml}
22
sentry:
33
options:
4-
before_breadcrumb: 'sentry_before_breadcrumb'
4+
before_breadcrumb: 'sentry.callback.before_breadcrumb'
55

66
services:
7-
sentry_before_breadcrumb:
8-
factory: ['@\App\Service\Sentry', 'getBeforeBreadcrumb']
7+
sentry.callback.before_breadcrumb:
8+
class: 'App\Service\Sentry'
9+
factory: [ '@App\Service\Sentry', 'getBeforeBreadcrumb' ]
910
```
1011
1112
The service needed for the `before_breadcrumb` option can be implemented as follows:
@@ -25,3 +26,9 @@ class Sentry
2526
}
2627
}
2728
```
29+
30+
<Note>
31+
32+
Learn more in [Callables in Symfony Options](/platforms/php/guides/symfony/configuration/symfony-options/#callables).
33+
34+
</Note>

src/includes/performance/always-inherit-sampling-decision/php.symfony.mdx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
```yaml {filename:config/packages/sentry.yaml}
22
sentry:
33
options:
4-
traces_sampler: 'sentry_traces_sampler'
4+
traces_sampler: 'sentry.callback.traces_sampler'
55

66
services:
7-
sentry_traces_sampler:
8-
factory: ['@\App\Service\Sentry', 'getTracesSampler']
7+
sentry.callback.traces_sampler:
8+
class: 'App\Service\Sentry'
9+
factory: [ '@App\Service\Sentry', 'getTracesSampler' ]
910
```
1011
1112
The service needed for the `traces_sampler` option can be implemented as follows:
@@ -30,3 +31,9 @@ class Sentry
3031
}
3132
}
3233
```
34+
35+
<Note>
36+
37+
Learn more in [Callables in Symfony Options](/platforms/php/guides/symfony/configuration/symfony-options/#callables).
38+
39+
</Note>

src/includes/performance/configure-sample-rate/php.symfony.mdx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ sentry:
44
# Specify a fixed sample rate:
55
traces_sample_rate: 1.0
66
# Or provide a custom sampler:
7-
traces_sampler: 'sentry_tracer_sampler'
7+
traces_sampler: 'sentry.callback.traces_sampler'
88

99
# Only needed when using the `traces_sampler`
1010
services:
11-
sentry_tracer_sampler:
12-
factory: ['@\App\Service\Sentry', 'getTracesSampler']
11+
sentry.callback.traces_sampler:
12+
class: 'App\Service\Sentry'
13+
factory: [ '@App\Service\Sentry', 'getTracesSampler' ]
1314
```
1415
1516
The service needed for the `traces_sampler` option can be implemented as follows:
@@ -29,3 +30,9 @@ class Sentry
2930
}
3031
}
3132
```
33+
34+
<Note>
35+
36+
Learn more in [Callables in Symfony Options](/platforms/php/guides/symfony/configuration/symfony-options/#callables).
37+
38+
</Note>

src/includes/performance/traces-sampler-as-filter/php.symfony.mdx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
```yaml {filename:config/packages/sentry.yaml}
22
sentry:
33
options:
4-
traces_sampler: 'sentry_traces_sampler'
4+
traces_sampler: 'sentry.callback.traces_sampler'
55

66
services:
7-
sentry_traces_sampler:
8-
factory: ['@\App\Service\Sentry', 'getTracesSampler']
7+
sentry.callback.traces_sampler:
8+
class: 'App\Service\Sentry'
9+
factory: [ '@App\Service\Sentry', 'getTracesSampler' ]
910
```
1011
1112
The service needed for the `traces_sampler` option can be implemented as follows:
@@ -37,3 +38,9 @@ class Sentry
3738
}
3839
}
3940
```
41+
42+
<Note>
43+
44+
Learn more in [Callables in Symfony Options](/platforms/php/guides/symfony/configuration/symfony-options/#callables).
45+
46+
</Note>

src/platforms/php/guides/symfony/configuration/symfony-options.mdx

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ sentry:
1616
register_error_listener: true
1717
options:
1818
attach_stacktrace: true
19-
before_breadcrumb: "@sentry.callback.before_breadcrumb"
20-
before_send: "@sentry.callback.before_send"
19+
before_breadcrumb: "sentry.callback.before_breadcrumb"
20+
before_send: "sentry.callback.before_send"
2121
capture_silenced_errors: false
2222
context_lines: 5
2323
default_integrations: true
@@ -30,7 +30,7 @@ sentry:
3030
- "%kernel.cache_dir%"
3131
- "%kernel.project_dir%/vendor"
3232
integrations:
33-
- "@sentry.integration.my_custom_integration"
33+
- "sentry.integration.my_custom_integration"
3434
logger: "php"
3535
max_breadcrumbs: 50
3636
max_value_length: 2048
@@ -39,7 +39,7 @@ sentry:
3939
release: "abcde12345"
4040
sample_rate: 1
4141
traces_sample_rate: 0
42-
traces_sampler: "@sentry.callback.traces_sampler"
42+
traces_sampler: "sentry.callback.traces_sampler"
4343
send_attempts: 3
4444
send_default_pii: false
4545
server_name: "www.example.com"
@@ -58,11 +58,6 @@ you can read more about those in the [general configuration docs](../options/).
5858
Below you can find additional documentation that is specific to the bundle usage, or information about the sensible default
5959
values that you can use in some cases.
6060

61-
## `before_breadcrumb`, `before_send` and `traces_sampler`
62-
63-
The `before_breadcrumb`, `before_send` and `traces_sampler` options accept a `callable`; thus, you cannot provide it directly through
64-
a YAML file; the bundle accepts a service reference (starting with `@`), which you can build in your DIC container.
65-
6661
## `environment`
6762

6863
The `environment` option defaults to the same environment of your Symfony application.
@@ -75,3 +70,37 @@ In this bundle it has three default values:
7570
- `%kernel.build_dir%`, to exclude Symfony's build dir
7671
- `%kernel.cache_dir%`, to exclude Symfony's cache dir
7772
- `%kernel.project_dir%/vendor`, to exclude Composer's dependencies
73+
74+
## Callables
75+
76+
The `before_breadcrumb`, `before_send` and `traces_sampler` options accept a `callable`; so, you cannot provide it directly through
77+
a YAML file. The bundle accepts a service reference, which you can build in your DIC container like this:
78+
79+
```yaml {filename:config/packages/sentry.yaml}
80+
sentry:
81+
options:
82+
before_send: 'sentry.callback.before_send'
83+
84+
services:
85+
sentry.callback.before_send:
86+
class: 'App\Service\Sentry'
87+
factory: [ '@App\Service\Sentry', 'getBeforeSend' ]
88+
```
89+
90+
The service needed for the `before_breadcrumb` option can be implemented as follows:
91+
92+
```php {filename:src/Service/Sentry.php}
93+
<?php
94+
95+
namespace App\Service;
96+
97+
class Sentry
98+
{
99+
public function getBeforeSend(): callable
100+
{
101+
return function(\Sentry\Event $event, ?\Sentry\EventHint $hint): ?\Sentry\Event {
102+
return $event;
103+
};
104+
}
105+
}
106+
```

0 commit comments

Comments
 (0)