Skip to content

Commit 88b0e41

Browse files
authored
1 parent dd36728 commit 88b0e41

File tree

6 files changed

+228
-7
lines changed

6 files changed

+228
-7
lines changed

static/app/components/onboarding/productSelection.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,16 @@ export const platformProductAvailability = {
236236
ProductSolution.LOGS,
237237
],
238238
'node-cloudflare-pages': [ProductSolution.PERFORMANCE_MONITORING, ProductSolution.LOGS],
239-
php: [ProductSolution.PERFORMANCE_MONITORING, ProductSolution.PROFILING],
240-
'php-laravel': [ProductSolution.PERFORMANCE_MONITORING, ProductSolution.PROFILING],
239+
php: [
240+
ProductSolution.PERFORMANCE_MONITORING,
241+
ProductSolution.PROFILING,
242+
ProductSolution.LOGS,
243+
],
244+
'php-laravel': [
245+
ProductSolution.PERFORMANCE_MONITORING,
246+
ProductSolution.PROFILING,
247+
ProductSolution.LOGS,
248+
],
241249
'php-symfony': [ProductSolution.PERFORMANCE_MONITORING, ProductSolution.PROFILING],
242250
python: [ProductSolution.PERFORMANCE_MONITORING, ProductSolution.PROFILING],
243251
'python-aiohttp': [ProductSolution.PERFORMANCE_MONITORING, ProductSolution.PROFILING],

static/app/gettingStartedDocs/php/laravel.spec.tsx

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import {renderWithOnboardingLayout} from 'sentry-test/onboarding/renderWithOnboa
22
import {screen} from 'sentry-test/reactTestingLibrary';
33
import {textWithMarkupMatcher} from 'sentry-test/utils';
44

5+
import {ProductSolution} from 'sentry/components/onboarding/gettingStartedDoc/types';
6+
57
import docs from './laravel';
68

79
describe('laravel onboarding docs', function () {
@@ -26,12 +28,57 @@ describe('laravel onboarding docs', function () {
2628

2729
// Does not render config option
2830
expect(
29-
screen.queryByText(textWithMarkupMatcher(/SENTRY_TRACES_SAMPLE_RATE=1\.0,/))
31+
screen.queryByText(textWithMarkupMatcher(/SENTRY_TRACES_SAMPLE_RATE=1\.0/))
3032
).not.toBeInTheDocument();
3133

3234
// Does not render config option
3335
expect(
34-
screen.queryByText(textWithMarkupMatcher(/SENTRY_PROFILES_SAMPLE_RATE=1\.0,/))
36+
screen.queryByText(textWithMarkupMatcher(/SENTRY_PROFILES_SAMPLE_RATE=1\.0/))
37+
).not.toBeInTheDocument();
38+
39+
// Does not render logs config options
40+
expect(
41+
screen.queryByText(textWithMarkupMatcher(/SENTRY_ENABLE_LOGS=true/))
42+
).not.toBeInTheDocument();
43+
expect(
44+
screen.queryByText(textWithMarkupMatcher(/LOG_CHANNEL=stack/))
45+
).not.toBeInTheDocument();
46+
expect(
47+
screen.queryByText(textWithMarkupMatcher(/LOG_STACK=single,sentry_logs/))
3548
).not.toBeInTheDocument();
3649
});
50+
51+
it('renders with logs selected', function () {
52+
renderWithOnboardingLayout(docs, {
53+
selectedProducts: [ProductSolution.ERROR_MONITORING, ProductSolution.LOGS],
54+
});
55+
56+
// Renders logs environment configuration
57+
expect(
58+
screen.getByText(textWithMarkupMatcher(/SENTRY_ENABLE_LOGS=true/))
59+
).toBeInTheDocument();
60+
expect(
61+
screen.getByText(textWithMarkupMatcher(/LOG_CHANNEL=stack/))
62+
).toBeInTheDocument();
63+
expect(
64+
screen.getByText(textWithMarkupMatcher(/LOG_STACK=single,sentry_logs/))
65+
).toBeInTheDocument();
66+
67+
// Renders logging.php configuration instructions
68+
expect(screen.getByText(textWithMarkupMatcher(/'sentry_logs'/))).toBeInTheDocument();
69+
expect(
70+
screen.getByText(textWithMarkupMatcher(/'driver' => 'sentry_logs'/))
71+
).toBeInTheDocument();
72+
73+
// Renders logs verification examples
74+
expect(
75+
screen.getByText(textWithMarkupMatcher(/Log::info\('This is an info message'\)/))
76+
).toBeInTheDocument();
77+
expect(
78+
screen.getByText(textWithMarkupMatcher(/Log::channel\('sentry'\)->error/))
79+
).toBeInTheDocument();
80+
expect(
81+
screen.getByText(textWithMarkupMatcher(/Sentry\\logger\(\)->info/))
82+
).toBeInTheDocument();
83+
});
3784
});

static/app/gettingStartedDocs/php/laravel.tsx

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ SENTRY_TRACES_SAMPLE_RATE=1.0`
5353
# Set a sampling rate for profiling - this is relative to traces_sample_rate
5454
SENTRY_PROFILES_SAMPLE_RATE=1.0`
5555
: ''
56+
}${
57+
params.isLogsSelected
58+
? `
59+
# Enable logs to be sent to Sentry
60+
SENTRY_ENABLE_LOGS=true
61+
# Configure logging to use both file and Sentry
62+
LOG_CHANNEL=stack
63+
LOG_STACK=single,sentry_logs`
64+
: ''
5665
}`;
5766

5867
const onboarding: OnboardingConfig = {
@@ -131,6 +140,26 @@ const onboarding: OnboardingConfig = {
131140
language: 'shell',
132141
code: getConfigureSnippet(params),
133142
},
143+
...(params.isLogsSelected
144+
? [
145+
{
146+
description: tct(
147+
'To configure Sentry as a log channel, add the following config to the [code:channels] section in [code:config/logging.php]. If this file does not exist, run [code:php artisan config:publish logging] to publish it:',
148+
{code: <code />}
149+
),
150+
language: 'php',
151+
code: `'channels' => [
152+
// ...
153+
'sentry_logs' => [
154+
'driver' => 'sentry_logs',
155+
// The minimum logging level at which this handler will be triggered
156+
// Available levels: debug, info, notice, warning, error, critical, alert, emergency
157+
'level' => env('LOG_LEVEL', 'info'), // defaults to \`debug\` if not set
158+
],
159+
],`,
160+
},
161+
]
162+
: []),
134163
{
135164
description: (
136165
<Alert.Container>
@@ -148,7 +177,7 @@ const onboarding: OnboardingConfig = {
148177
],
149178
},
150179
],
151-
verify: () => [
180+
verify: (params: Params) => [
152181
{
153182
type: StepType.VERIFY,
154183
configurations: [
@@ -162,6 +191,35 @@ const onboarding: OnboardingConfig = {
162191
language: 'shell',
163192
code: 'php artisan sentry:test',
164193
},
194+
...(params.isLogsSelected
195+
? [
196+
{
197+
description: tct(
198+
"Once you have configured Sentry as a log channel, you can use Laravel's built-in logging functionality to send logs to Sentry:",
199+
{code: <code />}
200+
),
201+
language: 'php',
202+
code: `use Illuminate\\Support\\Facades\\Log;
203+
204+
// Log to all channels in the stack (including Sentry)
205+
Log::info('This is an info message');
206+
Log::warning('User {id} failed to login.', ['id' => $user->id]);
207+
Log::error('This is an error message');
208+
209+
// Log directly to the Sentry channel
210+
Log::channel('sentry')->error('This will only go to Sentry');`,
211+
},
212+
{
213+
description: tct(
214+
'You can also test your configuration using the Sentry logger directly:',
215+
{code: <code />}
216+
),
217+
language: 'php',
218+
code: `\\Sentry\\logger()->info('A test log message');
219+
\\Sentry\\logger()->flush();`,
220+
},
221+
]
222+
: []),
165223
],
166224
},
167225
],

static/app/gettingStartedDocs/php/php.spec.tsx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import {renderWithOnboardingLayout} from 'sentry-test/onboarding/renderWithOnboa
22
import {screen} from 'sentry-test/reactTestingLibrary';
33
import {textWithMarkupMatcher} from 'sentry-test/utils';
44

5+
import {ProductSolution} from 'sentry/components/onboarding/gettingStartedDoc/types';
6+
57
import docs from './php';
68

79
describe('php onboarding docs', function () {
@@ -33,5 +35,51 @@ describe('php onboarding docs', function () {
3335
expect(
3436
screen.queryByText(textWithMarkupMatcher(/'profiles_sample_rate' => 1\.0,/))
3537
).not.toBeInTheDocument();
38+
39+
// Does not render logs config option
40+
expect(
41+
screen.queryByText(textWithMarkupMatcher(/'enable_logs' => true,/))
42+
).not.toBeInTheDocument();
43+
});
44+
45+
it('renders with logs selected', function () {
46+
renderWithOnboardingLayout(docs, {
47+
selectedProducts: [ProductSolution.ERROR_MONITORING, ProductSolution.LOGS],
48+
});
49+
50+
// Renders logs configuration
51+
expect(
52+
screen.getByText(textWithMarkupMatcher(/'enable_logs' => true,/))
53+
).toBeInTheDocument();
54+
55+
// Ensure other config options are not rendered when not selected
56+
expect(
57+
screen.queryByText(textWithMarkupMatcher(/'traces_sample_rate' => 1\.0,/))
58+
).not.toBeInTheDocument();
59+
expect(
60+
screen.queryByText(textWithMarkupMatcher(/'profiles_sample_rate' => 1\.0,/))
61+
).not.toBeInTheDocument();
62+
});
63+
64+
it('renders with all products selected', function () {
65+
renderWithOnboardingLayout(docs, {
66+
selectedProducts: [
67+
ProductSolution.ERROR_MONITORING,
68+
ProductSolution.PERFORMANCE_MONITORING,
69+
ProductSolution.PROFILING,
70+
ProductSolution.LOGS,
71+
],
72+
});
73+
74+
// Renders all configuration options
75+
expect(
76+
screen.getByText(textWithMarkupMatcher(/'traces_sample_rate' => 1\.0,/))
77+
).toBeInTheDocument();
78+
expect(
79+
screen.getByText(textWithMarkupMatcher(/'profiles_sample_rate' => 1\.0,/))
80+
).toBeInTheDocument();
81+
expect(
82+
screen.getByText(textWithMarkupMatcher(/'enable_logs' => true,/))
83+
).toBeInTheDocument();
3684
});
3785
});

static/app/gettingStartedDocs/php/php.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ const getConfigureSnippet = (params: Params) => `\\Sentry\\init([
3232
// Set a sampling rate for profiling - this is relative to traces_sample_rate
3333
'profiles_sample_rate' => 1.0,`
3434
: ''
35+
}${
36+
params.isLogsSelected
37+
? `
38+
// Enable logs to be sent to Sentry
39+
'enable_logs' => true,`
40+
: ''
3541
}
3642
]);`;
3743

static/app/gettingStartedDocs/php/symfony.spec.tsx

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import {renderWithOnboardingLayout} from 'sentry-test/onboarding/renderWithOnboa
22
import {screen} from 'sentry-test/reactTestingLibrary';
33
import {textWithMarkupMatcher} from 'sentry-test/utils';
44

5+
import {ProductSolution} from 'sentry/components/onboarding/gettingStartedDoc/types';
6+
57
import docs from './symfony';
68

79
describe('symfony onboarding docs', function () {
@@ -26,12 +28,64 @@ describe('symfony onboarding docs', function () {
2628

2729
// Does not render config option
2830
expect(
29-
screen.queryByText(textWithMarkupMatcher(/traces_sample_rate: 1\.0,/))
31+
screen.queryByText(textWithMarkupMatcher(/traces_sample_rate: 1\.0/))
3032
).not.toBeInTheDocument();
3133

3234
// Does not render config option
3335
expect(
34-
screen.queryByText(textWithMarkupMatcher(/profiles_sample_rate: 1\.0,/))
36+
screen.queryByText(textWithMarkupMatcher(/profiles_sample_rate: 1\.0/))
37+
).not.toBeInTheDocument();
38+
39+
// Does not render the YAML configuration section at all
40+
expect(
41+
screen.queryByText(textWithMarkupMatcher(/config\/packages\/sentry\.yaml/))
3542
).not.toBeInTheDocument();
3643
});
44+
45+
it('renders with performance monitoring selected', function () {
46+
renderWithOnboardingLayout(docs, {
47+
selectedProducts: [
48+
ProductSolution.ERROR_MONITORING,
49+
ProductSolution.PERFORMANCE_MONITORING,
50+
],
51+
});
52+
53+
// Renders performance configuration
54+
expect(
55+
screen.getByText(textWithMarkupMatcher(/traces_sample_rate: 1\.0/))
56+
).toBeInTheDocument();
57+
58+
// Renders the YAML configuration file instruction
59+
expect(
60+
screen.getByText(textWithMarkupMatcher(/config\/packages\/sentry\.yaml/))
61+
).toBeInTheDocument();
62+
63+
// Ensure other config options are not rendered when not selected
64+
expect(
65+
screen.queryByText(textWithMarkupMatcher(/profiles_sample_rate: 1\.0/))
66+
).not.toBeInTheDocument();
67+
});
68+
69+
it('renders with all products selected', function () {
70+
renderWithOnboardingLayout(docs, {
71+
selectedProducts: [
72+
ProductSolution.ERROR_MONITORING,
73+
ProductSolution.PERFORMANCE_MONITORING,
74+
ProductSolution.PROFILING,
75+
],
76+
});
77+
78+
// Renders all configuration options
79+
expect(
80+
screen.getByText(textWithMarkupMatcher(/traces_sample_rate: 1\.0/))
81+
).toBeInTheDocument();
82+
expect(
83+
screen.getByText(textWithMarkupMatcher(/profiles_sample_rate: 1\.0/))
84+
).toBeInTheDocument();
85+
86+
// Renders the YAML configuration file instruction
87+
expect(
88+
screen.getByText(textWithMarkupMatcher(/config\/packages\/sentry\.yaml/))
89+
).toBeInTheDocument();
90+
});
3791
});

0 commit comments

Comments
 (0)