Skip to content

Commit 3ac4547

Browse files
authored
feat(logs): add options to enable logging (#939)
1 parent e8022fe commit 3ac4547

File tree

9 files changed

+23
-2
lines changed

9 files changed

+23
-2
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"php": "^7.2||^8.0",
1616
"guzzlehttp/psr7": "^2.1.1",
1717
"jean85/pretty-package-versions": "^1.5||^2.0",
18-
"sentry/sentry": "^4.14.1",
18+
"sentry/sentry": "^4.15.0",
1919
"symfony/cache-contracts": "^1.1||^2.4||^3.0",
2020
"symfony/config": "^4.4.20||^5.0.11||^6.0||^7.0",
2121
"symfony/console": "^4.4.20||^5.0.11||^6.0||^7.0",

phpstan-baseline.neon

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ parameters:
8585
count: 1
8686
path: src/DependencyInjection/SentryExtension.php
8787

88+
-
89+
message: "#^Cannot access offset 'before_send_logs' on mixed\\.$#"
90+
count: 1
91+
path: src/DependencyInjection/SentryExtension.php
92+
8893
-
8994
message: "#^Parameter \\#1 \\$array of function array_filter expects array, mixed given\\.$#"
9095
count: 1
@@ -97,7 +102,7 @@ parameters:
97102

98103
-
99104
message: "#^Parameter \\#1 \\$id of class Symfony\\\\Component\\\\DependencyInjection\\\\Reference constructor expects string, mixed given\\.$#"
100-
count: 10
105+
count: 11
101106
path: src/DependencyInjection/SentryExtension.php
102107

103108
-

src/DependencyInjection/Configuration.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public function getConfigTreeBuilder(): TreeBuilder
8585
->max(1.0)
8686
->info('The sampling factor to apply to profiles. A value of 0 will deny sending any profiles, and a value of 1 will send all profiles. Profiles are sampled in relation to traces_sample_rate')
8787
->end()
88+
->booleanNode('enable_logs')->end()
8889
->booleanNode('attach_stacktrace')->end()
8990
->booleanNode('attach_metric_code_locations')->end()
9091
->integerNode('context_lines')->min(0)->end()
@@ -112,6 +113,7 @@ public function getConfigTreeBuilder(): TreeBuilder
112113
->scalarNode('before_send_transaction')->end()
113114
->scalarNode('before_send_check_in')->end()
114115
->scalarNode('before_send_metrics')->end()
116+
->scalarNode('before_send_logs')->end()
115117
->variableNode('trace_propagation_targets')->end()
116118
->arrayNode('tags')
117119
->useAttributeAsKey('name')

src/DependencyInjection/SentryExtension.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ private function registerConfiguration(ContainerBuilder $container, array $confi
124124
$options['before_send_metrics'] = new Reference($options['before_send_metrics']);
125125
}
126126

127+
if (isset($options['before_send_logs'])) {
128+
$options['before_send_logs'] = new Reference($options['before_send_logs']);
129+
}
130+
127131
if (isset($options['before_breadcrumb'])) {
128132
$options['before_breadcrumb'] = new Reference($options['before_breadcrumb']);
129133
}

src/Resources/config/schema/sentry-1.0.xsd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
<xsd:attribute name="default-integrations" type="xsd:boolean" />
3838
<xsd:attribute name="sample-rate" type="xsd:float" />
3939
<xsd:attribute name="enable-tracing" type="xsd:boolean" />
40+
<xsd:attribute name="enable-logs" type="xsd:boolean" />
4041
<xsd:attribute name="traces-sample-rate" type="xsd:float" />
4142
<xsd:attribute name="profiles-sample-rate" type="xsd:float" />
4243
<xsd:attribute name="traces-sampler" type="xsd:string" />
@@ -54,6 +55,7 @@
5455
<xsd:attribute name="before-send-transaction" type="xsd:string" />
5556
<xsd:attribute name="before-send-check-in" type="xsd:string" />
5657
<xsd:attribute name="before-send-metrics" type="xsd:string" />
58+
<xsd:attribute name="before-send-logs" type="xsd:string" />
5759
<xsd:attribute name="error-types" type="xsd:string" />
5860
<xsd:attribute name="max-breadcrumbs" type="xsd:integer" />
5961
<xsd:attribute name="before-breadcrumb" type="xsd:string" />

tests/DependencyInjection/Fixtures/php/full.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
'traces_sample_rate' => 1,
1818
'traces_sampler' => 'App\\Sentry\\Tracing\\TracesSampler',
1919
'profiles_sample_rate' => 1,
20+
'enable_logs' => true,
2021
'attach_stacktrace' => true,
2122
'attach_metric_code_locations' => true,
2223
'context_lines' => 0,
@@ -32,6 +33,7 @@
3233
'before_send_transaction' => 'App\\Sentry\\BeforeSendTransactionCallback',
3334
'before_send_check_in' => 'App\\Sentry\\BeforeSendCheckInCallback',
3435
'before_send_metrics' => 'App\\Sentry\\BeforeSendMetricsCallback',
36+
'before_send_logs' => 'App\\Sentry\\BeforeSendLogsCallback',
3537
'trace_propagation_targets' => ['website.invalid'],
3638
'tags' => [
3739
'context' => 'development',

tests/DependencyInjection/Fixtures/xml/full.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<sentry:options default-integrations="false"
1414
sample-rate="1"
1515
enable-tracing="true"
16+
enable-logs="true"
1617
traces-sample-rate="1"
1718
traces-sampler="App\Sentry\Tracing\TracesSampler"
1819
profiles-sample-rate="1"
@@ -29,6 +30,7 @@
2930
before-send-transaction="App\Sentry\BeforeSendTransactionCallback"
3031
before-send-check-in="App\Sentry\BeforeSendCheckInCallback"
3132
before-send-metrics="App\Sentry\BeforeSendMetricsCallback"
33+
before-send-logs="App\Sentry\BeforeSendLogsCallback"
3234
error-types="E_ALL"
3335
max-breadcrumbs="1"
3436
before-breadcrumb="App\Sentry\BeforeBreadcrumbCallback"

tests/DependencyInjection/Fixtures/yml/full.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ sentry:
1212
traces_sample_rate: 1
1313
traces_sampler: App\Sentry\Tracing\TracesSampler
1414
profiles_sample_rate: 1
15+
enable_logs: true
1516
attach_stacktrace: true
1617
attach_metric_code_locations: true
1718
context_lines: 0
@@ -29,6 +30,7 @@ sentry:
2930
before_send_transaction: App\Sentry\BeforeSendTransactionCallback
3031
before_send_check_in: App\Sentry\BeforeSendCheckInCallback
3132
before_send_metrics: App\Sentry\BeforeSendMetricsCallback
33+
before_send_logs: App\Sentry\BeforeSendLogsCallback
3234
trace_propagation_targets:
3335
- 'website.invalid'
3436
tags:

tests/DependencyInjection/SentryExtensionTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ public function testClientIsCreatedFromOptions(): void
209209
'traces_sample_rate' => 1,
210210
'traces_sampler' => new Reference('App\\Sentry\\Tracing\\TracesSampler'),
211211
'profiles_sample_rate' => 1,
212+
'enable_logs' => true,
212213
'attach_stacktrace' => true,
213214
'attach_metric_code_locations' => true,
214215
'context_lines' => 0,
@@ -228,6 +229,7 @@ public function testClientIsCreatedFromOptions(): void
228229
'before_send_transaction' => new Reference('App\\Sentry\\BeforeSendTransactionCallback'),
229230
'before_send_check_in' => new Reference('App\\Sentry\\BeforeSendCheckInCallback'),
230231
'before_send_metrics' => new Reference('App\\Sentry\\BeforeSendMetricsCallback'),
232+
'before_send_logs' => new Reference('App\\Sentry\\BeforeSendLogsCallback'),
231233
'trace_propagation_targets' => ['website.invalid'],
232234
'tags' => [
233235
'context' => 'development',

0 commit comments

Comments
 (0)