# Content

# Setup

Install composer package.

composer require contributte/sentry
1

Register Nette extension.

extensions:
    # Nette 3+
    sentry: Contributte\Sentry\DI\SentryExtension

    # Nette 2.4
    sentry: Contributte\Sentry\DI\SentryExtension24
1
2
3
4
5
6

# Configuration

Minimal configuration could look like this:

sentry:
    # Enabled only on production
    enable: %productionMode%

    # Client configuration
    client:
        dsn: "https://{KEY1}@{KEY2}.ingest.sentry.io/{KEY3}"
1
2
3
4
5
6
7

Full configuration could look like this:

sentry:
    # Enable / disable on local or producation
    enable: %productionMode%

    # Enable / disable build-in and Nette integrations
    integrations: true

    # Sentry logger configuration
    logger:
        # Capture messages [Debugger::log("this is error")]
        captureMessages: true

        # Capture levels [Debugger::log("this is error", "error")]
        captureLevels:
            # - debug
            # - info
            - warning
            - error
            - exception
            - critical

    # Sentry client configuration
    client:

        # Disable integrations in sentry.integrations if you want to override this list
        integrations: [
            # Sentry
            Sentry\Integration\EnvironmentIntegration()
            Sentry\Integration\ErrorListenerIntegration()
            Sentry\Integration\ExceptionListenerIntegration()
            Sentry\Integration\FatalErrorListenerIntegration()
            Sentry\Integration\FrameContextifierIntegration(null)
            Sentry\Integration\ModulesIntegration()
            Sentry\Integration\RequestIntegration(null)
            Sentry\Integration\TransactionIntegration()
            # Nette
            Contributte\Sentry\Integration\NetteApplicationIntegration()
            Contributte\Sentry\Integration\NetteHttpIntegration()
            Contributte\Sentry\Integration\NetteSecurityIntegration()
            Contributte\Sentry\Integration\NetteSessionIntegration()
            Contributte\Sentry\Integration\ExtraIntegration([
                # version: %appVersion%
            ])
        ]
        default_integrations: false
        send_attempts: 3
        prefixes: [%appDir%]
        sample_rate: 1
        attach_stacktrace: true
        context_lines: 6
        enable_compression: true
        environment: local
        logger: php
        release: latest
        dsn: "https://{KEY1}@{KEY2}.ingest.sentry.io/{KEY3}"
        server_name: ::gethostname()
        # before_send: ()
        tags:
            # version: %appVersion%
        error_types: 32767 # E_ALL
        max_breadcrumbs: 100
        # before_breadcrumb: ()
        in_app_exclude: []
        send_default_pii: true
        max_value_length: 1024
        http_proxy: null
        capture_silenced_errors: false
        max_request_body_size: always
        class_serializers: []
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69

See more about configuration under key sentry in official documentation (opens new window).

# Extra

# Integrations

Integrations are some kind of plugins for Sentry SDK. This package brings several integrations.

NetteApplicationIntegration

Add information about nette/application to Sentry event.

sentry:
    client:
        integrations:
            - Contributte\Sentry\Integration\NetteApplicationIntegration()
1
2
3
4

NetteHttpIntegration

Add information about nette/http to Sentry event.

sentry:
    client:
        integrations:
            - Contributte\Sentry\Integration\NetteHttpIntegration()
1
2
3
4

NetteSecurityIntegration

Add information about nette/security to Sentry event.

sentry:
    client:
        integrations:
            - Contributte\Sentry\Integration\NetteSecurityIntegration()
1
2
3
4

NetteSessionIntegration

Add information about nette/session to Sentry event.

sentry:
    client:
        integrations:
            - Contributte\Sentry\Integration\NetteSessionIntegration()
1
2
3
4

ExtraIntegration

Add extra data to Sentry event.

sentry:
    client:
        integrations:
            - Contributte\Sentry\Integration\ExtraIntegration([
                version: %appVersion%
            ])
1
2
3
4
5
6

# Usage

Sentry is successfully integrated to your Nette (opens new window) application and listen for any errors using Tracy (opens new window).

Let's test it using this smelling code.

<?php declare(strict_types=1);

namespace App;

use Nette\Application\UI\Presenter;

class HomePresenter extends Presenter
{

    public function actionDefault(): void
    {
        throw new \RuntimeException('This is example error');
    }

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

# Examples

There is example project contributte/sentry-skeleton (opens new window).