Skip to content

Commit

Permalink
added service.environment to set environment name (e.g. "production")
Browse files Browse the repository at this point in the history
  • Loading branch information
beniwohli committed Dec 29, 2017
1 parent ca27aad commit a110bca
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ https://github.com/elastic/apm-agent-python/compare/v1.0.0\...master[Check the H
* moved the library-frame detection from a processor to the stacktrace collection ({pull}113[#113]).
* added settings to enable/disable source code collection and local variables collection
for errors and transactions ({pull}117[#117])
* added `service.environment` to provide an environment name (e.g. "production", "staging") ({pull}123[#123])
* BREAKING: Several settings and APIs have been renamed ({pull}111[#111], {pull}119[#119]):
** The decorator for custom instrumentation, `elasticapm.trace`, is now `elasticapm.capture_span`
** The setting `traces_send_frequency` has been renamed to `transaction_send_frequency`.
Expand Down
13 changes: 13 additions & 0 deletions docs/configuration.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,19 @@ Note however that this can have adverse effects on performance.
[[other-options]]
=== Other options

[float]
[[config-environment]]
==== `environment`

[options="header"]
|============
| Environment | Django/Flask | Default | Example
| `ELASTIC_APM_ENVIRONMENT` | `ENVIRONMENT` | `None` | `"production"`
|============

The name of the environment this service is deployed in,
e.g. "production" or "staging".

[float]
[[config-secret-token]]
==== `secret_token`
Expand Down
1 change: 1 addition & 0 deletions elasticapm/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ def get_service_info(self):
runtime_version = language_version
result = {
'name': self.config.service_name,
'environment': self.config.environment,
'version': self.config.app_version,
'agent': {
'name': 'python',
Expand Down
1 change: 1 addition & 0 deletions elasticapm/conf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ def errors(self):
class Config(_ConfigBase):
service_name = _ConfigValue('SERVICE_NAME', validators=[lambda val: re.match('^[a-zA-Z0-9 _-]+$', val)],
required=True)
environment = _ConfigValue('ENVIRONMENT', default=None)
secret_token = _ConfigValue('SECRET_TOKEN')
debug = _BoolConfigValue('DEBUG', default=False)
server_url = _ConfigValue('SERVER_URL', default='http://localhost:8200', required=True)
Expand Down
14 changes: 9 additions & 5 deletions tests/client/client_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,18 @@ def send(self, data, headers):
pass


def test_app_info(elasticapm_client):
app_info = elasticapm_client.get_service_info()
assert app_info['name'] == elasticapm_client.config.service_name
assert app_info['language'] == {
@pytest.mark.parametrize('elasticapm_client', [
{'environment': 'production'}
], indirect=True)
def test_service_info(elasticapm_client):
service_info = elasticapm_client.get_service_info()
assert service_info['name'] == elasticapm_client.config.service_name
assert service_info['environment'] == elasticapm_client.config.environment == 'production'
assert service_info['language'] == {
'name': 'python',
'version': platform.python_version()
}
assert app_info['agent']['name'] == 'python'
assert service_info['agent']['name'] == 'python'


def test_system_info(elasticapm_client):
Expand Down

0 comments on commit a110bca

Please sign in to comment.