import ExternalLink from 'sentry/components/links/externalLink';
import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
import {
Docs,
DocsParams,
OnboardingConfig,
} from 'sentry/components/onboarding/gettingStartedDoc/types';
import replayOnboardingJsLoader from 'sentry/gettingStartedDocs/javascript/jsLoader/jsLoader';
import {t, tct} from 'sentry/locale';
type Params = DocsParams;
const getConfigureSnippet = (params: Params) => `\\Sentry\\init([
'dsn' => '${params.dsn}',${
params.isPerformanceSelected
? `
// Specify a fixed sample rate
'traces_sample_rate' => 1.0,`
: ''
}${
params.isProfilingSelected
? `
// Set a sampling rate for profiling - this is relative to traces_sample_rate
'profiles_sample_rate' => 1.0,`
: ''
}
]);`;
const getMetricsConfigureSnippet = () => `
use function \\Sentry\\init;
\\Sentry\\init([
'metric_code_locations' => true,
]);`;
const getVerifySnippet = () => `
try {
$this->functionFailsForSure();
} catch (\\Throwable $exception) {
\\Sentry\\captureException($exception);
}`;
const getMetricsVerifySnippet = () => `
use function \\Sentry\\metrics;
// Add 4 to a counter named 'hits'
metrics()->increment('hits', 4);
metrics()->flush();
// We recommend registering the flushing in a shutdownhandler
register_shutdown_function(static fn () => metrics()->flush());`;
const onboarding: OnboardingConfig = {
install: params => [
{
type: StepType.INSTALL,
description: tct(
'To install the PHP SDK, you need to be using Composer in your project. For more details about Composer, see the [composerDocumentationLink:Composer documentation].',
{
composerDocumentationLink:
{tct(
'To instrument certain regions of your code, you can [instrumentationLink:create transactions to capture them].',
{
instrumentationLink: (
,
}
),
configurations: [
{
language: 'bash',
code: 'composer install sentry/sentry',
},
],
},
],
configure: () => [
{
type: StepType.CONFIGURE,
description: t(
'Once the SDK is installed or updated, you can enable code locations being emitted with your metrics:'
),
configurations: [
{
code: [
{
label: 'PHP',
value: 'php',
language: 'php',
code: getMetricsConfigureSnippet(),
},
],
},
],
},
],
verify: () => [
{
type: StepType.VERIFY,
description: tct(
"Then you'll be able to add metrics as [codeCounters:counters], [codeSets:sets], [codeDistribution:distributions], and [codeGauge:gauges]. Try out this example:",
{
codeCounters:
,
codeSets:
,
codeDistribution:
,
codeGauge:
,
codeNamespace:
,
}
),
configurations: [
{
code: [
{
label: 'PHP',
value: 'php',
language: 'php',
code: getMetricsVerifySnippet(),
},
],
},
{
description: t(
'With a bit of delay you can see the data appear in the Sentry UI.'
),
},
{
description: tct(
'Learn more about metrics and how to configure them, by reading the [docsLink:docs].',
{
docsLink: (