Skip to content

Commit

Permalink
adding environment credencials
Browse files Browse the repository at this point in the history
  • Loading branch information
cauemarcondes committed Jun 18, 2021
1 parent 7e441d2 commit 0225a8c
Show file tree
Hide file tree
Showing 23 changed files with 859 additions and 355 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export function Instruction({
textPre,
replaceTemplateStrings,
customComponentName,
variantId,
isCloudEnabled,
}) {
const { tutorialService, http, uiSettings, getBasePath } = getServices();

Expand Down Expand Up @@ -96,18 +98,20 @@ export function Instruction({

{commandBlock}

{post}

{LazyCustomComponent && (
<Suspense fallback={<EuiLoadingSpinner />}>
<LazyCustomComponent
basePath={getBasePath()}
isDarkTheme={uiSettings.get('theme:darkMode')}
http={http}
variantId={variantId}
isCloudEnabled={isCloudEnabled}
/>
</Suspense>
)}

{post}

<EuiSpacer />
</div>
);
Expand All @@ -120,4 +124,6 @@ Instruction.propTypes = {
textPre: PropTypes.string,
replaceTemplateStrings: PropTypes.func.isRequired,
customComponentName: PropTypes.string,
variantId: PropTypes.string,
isCloudEnabled: PropTypes.bool.isRequired,
};
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ class InstructionSetUi extends React.Component {
textPost={instruction.textPost}
replaceTemplateStrings={this.props.replaceTemplateStrings}
customComponentName={instruction.customComponentName}
variantId={instructionVariant.id}
isCloudEnabled={this.props.isCloudEnabled}
/>
);
return {
Expand Down Expand Up @@ -320,6 +322,7 @@ InstructionSetUi.propTypes = {
paramValues: PropTypes.object.isRequired,
setParameter: PropTypes.func,
replaceTemplateStrings: PropTypes.func.isRequired,
isCloudEnabled: PropTypes.bool.isRequired,
};

export const InstructionSet = injectI18n(InstructionSetUi);
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ class TutorialUi extends React.Component {
setParameter={this.setParameter}
replaceTemplateStrings={this.props.replaceTemplateStrings}
key={index}
isCloudEnabled={this.props.isCloudEnabled}
/>
);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { i18n } from '@kbn/i18n';

export const django = `# ${i18n.translate(
'xpack.apm.tutorial.djangoClient.configure.commands.addAgentComment',
{
defaultMessage: 'Add the agent to the installed apps',
}
)}
INSTALLED_APPS = (
'elasticapm.contrib.django',
# ...
)
ELASTIC_APM = {curlyOpen}
# ${i18n.translate(
'xpack.apm.tutorial.djangoClient.configure.commands.setRequiredServiceNameComment',
{
defaultMessage: 'Set the required service name. Allowed characters:',
}
)}
# ${i18n.translate(
'xpack.apm.tutorial.djangoClient.configure.commands.allowedCharactersComment',
{
defaultMessage: 'a-z, A-Z, 0-9, -, _, and space',
}
)}
'SERVICE_NAME': '',
# ${i18n.translate(
'xpack.apm.tutorial.djangoClient.configure.commands.useIfApmServerRequiresTokenComment',
{
defaultMessage: 'Use if APM Server requires a secret token',
}
)}
'SECRET_TOKEN': '{{secretToken}}',
# ${i18n.translate(
'xpack.apm.tutorial.djangoClient.configure.commands.setCustomApmServerUrlComment',
{
defaultMessage:
'Set the custom APM Server URL (default: {defaultApmServerUrl})',
values: { defaultApmServerUrl: 'http://localhost:8200' },
}
)}
'SERVER_URL': '{{apmServerUrl}}',
# ${i18n.translate(
'xpack.apm.tutorial.djangoClient.configure.commands.setServiceEnvironmentComment',
{
defaultMessage: 'Set the service environment',
}
)}
'ENVIRONMENT': 'production',
{curlyClose}
# ${i18n.translate(
'xpack.apm.tutorial.djangoClient.configure.commands.addTracingMiddlewareComment',
{
defaultMessage: 'To send performance metrics, add our tracing middleware:',
}
)}
MIDDLEWARE = (
'elasticapm.contrib.django.middleware.TracingMiddleware',
#...
)`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
// TODO: ${'http://localhost:8200'}' fallback server_url

export const dotnet = `{
"ElasticApm": {
"SecretToken": "{{secretToken}}",
"ServerUrls": "{{apmServerUrl}}", //Set custom APM Server URL (default: http://localhost:8200)
"ServiceName": "MyApp", //allowed characters: a-z, A-Z, 0-9, -, _, and space. Default is the entry assembly of the application
"Environment": "production", // Set the service environment
}
}`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { i18n } from '@kbn/i18n';

export const flask = `# ${i18n.translate(
'xpack.apm.tutorial.flaskClient.configure.commands.initializeUsingEnvironmentVariablesComment',
{
defaultMessage: 'initialize using environment variables',
}
)}
from elasticapm.contrib.flask import ElasticAPM
app = Flask(__name__)
apm = ElasticAPM(app)
# ${i18n.translate(
'xpack.apm.tutorial.flaskClient.configure.commands.configureElasticApmComment',
{
defaultMessage:
"or configure to use ELASTIC_APM in your application's settings",
}
)}
from elasticapm.contrib.flask import ElasticAPM
app.config['ELASTIC_APM'] = {curlyOpen}
# ${i18n.translate(
'xpack.apm.tutorial.flaskClient.configure.commands.setRequiredServiceNameComment',
{
defaultMessage: 'Set the required service name. Allowed characters:',
}
)}
# ${i18n.translate(
'xpack.apm.tutorial.flaskClient.configure.commands.allowedCharactersComment',
{
defaultMessage: 'a-z, A-Z, 0-9, -, _, and space',
}
)}
'SERVICE_NAME': '',
# ${i18n.translate(
'xpack.apm.tutorial.flaskClient.configure.commands.useIfApmServerRequiresTokenComment',
{
defaultMessage: 'Use if APM Server requires a secret token',
}
)}
'SECRET_TOKEN': '{{secretToken}}',
# ${i18n.translate(
'xpack.apm.tutorial.flaskClient.configure.commands.setCustomApmServerUrlComment',
{
defaultMessage:
'Set the custom APM Server URL (default: {defaultApmServerUrl})',
values: { defaultApmServerUrl: 'http://localhost:8200' },
}
)}
'SERVER_URL': '{{apmServerUrl}}',
# ${i18n.translate(
'xpack.apm.tutorial.flaskClient.configure.commands.setServiceEnvironmentComment',
{
defaultMessage: 'Set the service environment',
}
)}
'ENVIRONMENT': 'production',
{curlyClose}
apm = ElasticAPM(app)`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import Mustache from 'mustache';
import { java } from './java';
import { node } from './node';
import { django } from './django';
import { flask } from './flask';
import { rails } from './rails';
import { rack } from './rack';
import { go } from './go';
import { dotnet } from './dotnet';
import { php } from './php';
import { rum, rumScript } from './rum';

const commands: Record<string, string> = {
java,
node,
django,
flask,
rails,
rack,
go,
dotnet,
php,
js: rum,
js_script: rumScript,
};

export function getCommands({
variantId,
environmentDetails,
}: {
variantId: string;
environmentDetails: {
apmServerUrl?: string;
secretToken?: string;
};
}) {
return Mustache.render(commands[variantId], environmentDetails);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { i18n } from '@kbn/i18n';

export const go = `# ${i18n.translate(
'xpack.apm.tutorial.goClient.configure.commands.initializeUsingEnvironmentVariablesComment',
{
defaultMessage: 'Initialize using environment variables:',
}
)}
# ${i18n.translate(
'xpack.apm.tutorial.goClient.configure.commands.setServiceNameComment',
{
defaultMessage:
'Set the service name. Allowed characters: # a-z, A-Z, 0-9, -, _, and space.',
}
)}
# ${i18n.translate(
'xpack.apm.tutorial.goClient.configure.commands.usedExecutableNameComment',
{
defaultMessage:
'If ELASTIC_APM_SERVICE_NAME is not specified, the executable name will be used.',
}
)}
export ELASTIC_APM_SERVICE_NAME=
# ${i18n.translate(
'xpack.apm.tutorial.goClient.configure.commands.setCustomApmServerUrlComment',
{
defaultMessage:
'Set custom APM Server URL (default: {defaultApmServerUrl})',
values: { defaultApmServerUrl: 'http://localhost:8200' },
}
)}
export ELASTIC_APM_SERVER_URL={{apmServerUrl}}
# ${i18n.translate(
'xpack.apm.tutorial.goClient.configure.commands.useIfApmRequiresTokenComment',
{
defaultMessage: 'Use if APM Server requires a secret token',
}
)}
export ELASTIC_APM_SECRET_TOKEN={{secretToken}}
# ${i18n.translate(
'xpack.apm.tutorial.goClient.configure.commands.setServiceEnvironment',
{
defaultMessage: 'Set the service environment',
}
)}
export ELASTIC_APM_ENVIRONMENT=
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export const java = `java -javaagent:/path/to/elastic-apm-agent-<version>.jar \\
-Delastic.apm.service_name=my-application \\
-Delastic.apm.server_urls= {{apmServerUrl}} \\
-Delastic.apm.secret_token= {{secretToken}} \\
-Delastic.apm.environment=production \\
-Delastic.apm.application_packages=org.example \\
-jar my-application.jar`;
Loading

0 comments on commit 0225a8c

Please sign in to comment.