Skip to content

Fix Symfony callback syntax #4658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 31, 2022
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
13 changes: 10 additions & 3 deletions src/includes/configuration/before-send-fingerprint/php.symfony.mdx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
```yaml {filename:config/packages/sentry.yaml}
sentry:
options:
before_send: 'sentry_before_send'
before_send: 'sentry.callback.before_send'

services:
sentry_before_send:
factory: ['@\App\Service\Sentry', 'getBeforeSend']
sentry.callback.before_send:
class: 'App\Service\Sentry'
factory: [ '@App\Service\Sentry', 'getBeforeSend' ]
```

The service needed for the `before_send` option can be implemented as follows:
Expand All @@ -29,3 +30,9 @@ class Sentry
}
}
```

<Note>

Learn more in [Callables in Symfony Options](/platforms/php/guides/symfony/configuration/symfony-options/#callables).

</Note>
13 changes: 10 additions & 3 deletions src/includes/configuration/before-send-hint/php.symfony.mdx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
```yaml {filename:config/packages/sentry.yaml}
sentry:
options:
before_send: 'sentry_before_send'
before_send: 'sentry.callback.before_send'

services:
sentry_before_send:
factory: ['@\App\Service\Sentry', 'getBeforeSend']
sentry.callback.before_send:
class: 'App\Service\Sentry'
factory: [ '@App\Service\Sentry', 'getBeforeSend' ]
```

The service needed for the `before_send` option can be implemented as follows:
Expand All @@ -30,3 +31,9 @@ class Sentry
}
}
```

<Note>

Learn more in [Callables in Symfony Options](/platforms/php/guides/symfony/configuration/symfony-options/#callables).

</Note>
13 changes: 10 additions & 3 deletions src/includes/configuration/before-send/php.symfony.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ In the Symfony config, a service can be used to modify the event or return a com
```yaml {filename:config/packages/sentry.yaml}
sentry:
options:
before_send: 'sentry_before_send'
before_send: 'sentry.callback.before_send'

services:
sentry_before_send:
factory: ['@\App\Service\Sentry', 'getBeforeSend']
sentry.callback.before_send:
class: 'App\Service\Sentry'
factory: [ '@App\Service\Sentry', 'getBeforeSend' ]
```

The service needed for the `before_send` option can be implemented as follows:
Expand All @@ -27,3 +28,9 @@ class Sentry
}
}
```

<Note>

Learn more in [Callables in Symfony Options](/platforms/php/guides/symfony/configuration/symfony-options/#callables).

</Note>
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
```yaml {filename:config/packages/sentry.yaml}
sentry:
options:
before_breadcrumb: 'sentry_before_breadcrumb'
before_breadcrumb: 'sentry.callback.before_breadcrumb'

services:
sentry_before_breadcrumb:
factory: ['@\App\Service\Sentry', 'getBeforeBreadcrumb']
sentry.callback.before_breadcrumb:
class: 'App\Service\Sentry'
factory: [ '@App\Service\Sentry', 'getBeforeBreadcrumb' ]
```

The service needed for the `before_breadcrumb` option can be implemented as follows:
Expand All @@ -25,3 +26,9 @@ class Sentry
}
}
```

<Note>

Learn more in [Callables in Symfony Options](/platforms/php/guides/symfony/configuration/symfony-options/#callables).

</Note>
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
```yaml {filename:config/packages/sentry.yaml}
sentry:
options:
traces_sampler: 'sentry_traces_sampler'
traces_sampler: 'sentry.callback.traces_sampler'

services:
sentry_traces_sampler:
factory: ['@\App\Service\Sentry', 'getTracesSampler']
sentry.callback.traces_sampler:
class: 'App\Service\Sentry'
factory: [ '@App\Service\Sentry', 'getTracesSampler' ]
```

The service needed for the `traces_sampler` option can be implemented as follows:
Expand All @@ -30,3 +31,9 @@ class Sentry
}
}
```

<Note>

Learn more in [Callables in Symfony Options](/platforms/php/guides/symfony/configuration/symfony-options/#callables).

</Note>
13 changes: 10 additions & 3 deletions src/includes/performance/configure-sample-rate/php.symfony.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ sentry:
# Specify a fixed sample rate:
traces_sample_rate: 1.0
# Or provide a custom sampler:
traces_sampler: 'sentry_tracer_sampler'
traces_sampler: 'sentry.callback.traces_sampler'

# Only needed when using the `traces_sampler`
services:
sentry_tracer_sampler:
factory: ['@\App\Service\Sentry', 'getTracesSampler']
sentry.callback.traces_sampler:
class: 'App\Service\Sentry'
factory: [ '@App\Service\Sentry', 'getTracesSampler' ]
```

The service needed for the `traces_sampler` option can be implemented as follows:
Expand All @@ -29,3 +30,9 @@ class Sentry
}
}
```

<Note>

Learn more in [Callables in Symfony Options](/platforms/php/guides/symfony/configuration/symfony-options/#callables).

</Note>
13 changes: 10 additions & 3 deletions src/includes/performance/traces-sampler-as-filter/php.symfony.mdx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
```yaml {filename:config/packages/sentry.yaml}
sentry:
options:
traces_sampler: 'sentry_traces_sampler'
traces_sampler: 'sentry.callback.traces_sampler'

services:
sentry_traces_sampler:
factory: ['@\App\Service\Sentry', 'getTracesSampler']
sentry.callback.traces_sampler:
class: 'App\Service\Sentry'
factory: [ '@App\Service\Sentry', 'getTracesSampler' ]
```

The service needed for the `traces_sampler` option can be implemented as follows:
Expand Down Expand Up @@ -37,3 +38,9 @@ class Sentry
}
}
```

<Note>

Learn more in [Callables in Symfony Options](/platforms/php/guides/symfony/configuration/symfony-options/#callables).

</Note>
47 changes: 38 additions & 9 deletions src/platforms/php/guides/symfony/configuration/symfony-options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ sentry:
register_error_listener: true
options:
attach_stacktrace: true
before_breadcrumb: "@sentry.callback.before_breadcrumb"
before_send: "@sentry.callback.before_send"
before_breadcrumb: "sentry.callback.before_breadcrumb"
before_send: "sentry.callback.before_send"
capture_silenced_errors: false
context_lines: 5
default_integrations: true
Expand All @@ -30,7 +30,7 @@ sentry:
- "%kernel.cache_dir%"
- "%kernel.project_dir%/vendor"
integrations:
- "@sentry.integration.my_custom_integration"
- "sentry.integration.my_custom_integration"
logger: "php"
max_breadcrumbs: 50
max_value_length: 2048
Expand All @@ -39,7 +39,7 @@ sentry:
release: "abcde12345"
sample_rate: 1
traces_sample_rate: 0
traces_sampler: "@sentry.callback.traces_sampler"
traces_sampler: "sentry.callback.traces_sampler"
send_attempts: 3
send_default_pii: false
server_name: "www.example.com"
Expand All @@ -58,11 +58,6 @@ you can read more about those in the [general configuration docs](../options/).
Below you can find additional documentation that is specific to the bundle usage, or information about the sensible default
values that you can use in some cases.

## `before_breadcrumb`, `before_send` and `traces_sampler`

The `before_breadcrumb`, `before_send` and `traces_sampler` options accept a `callable`; thus, you cannot provide it directly through
a YAML file; the bundle accepts a service reference (starting with `@`), which you can build in your DIC container.

## `environment`

The `environment` option defaults to the same environment of your Symfony application.
Expand All @@ -75,3 +70,37 @@ In this bundle it has three default values:
- `%kernel.build_dir%`, to exclude Symfony's build dir
- `%kernel.cache_dir%`, to exclude Symfony's cache dir
- `%kernel.project_dir%/vendor`, to exclude Composer's dependencies

## Callables

The `before_breadcrumb`, `before_send` and `traces_sampler` options accept a `callable`; so, you cannot provide it directly through
a YAML file. The bundle accepts a service reference, which you can build in your DIC container like this:

```yaml {filename:config/packages/sentry.yaml}
sentry:
options:
before_send: 'sentry.callback.before_send'

services:
sentry.callback.before_send:
class: 'App\Service\Sentry'
factory: [ '@App\Service\Sentry', 'getBeforeSend' ]
```

The service needed for the `before_breadcrumb` option can be implemented as follows:

```php {filename:src/Service/Sentry.php}
<?php

namespace App\Service;

class Sentry
{
public function getBeforeSend(): callable
{
return function(\Sentry\Event $event, ?\Sentry\EventHint $hint): ?\Sentry\Event {
return $event;
};
}
}
```