Annotation API

The Annotation API allows you to annotate visualizations in the APM app with significant events, like deployments, allowing you to easily see how these events are impacting the performance of your existing applications.

By default, annotations are stored in a newly created observability-annotations index. The name of this index can be changed in your config.yml by editing xpack.observability.annotations.index. If you change the default index name, you’ll also need to update your user privileges accordingly.

The following APIs are available:

How to use APM APIs

Expand for required headers, privileges, and usage details

Interact with APM APIs using cURL or another API tool. All APM APIs are Kibana APIs, not Elasticsearch APIs; because of this, the Kibana dev tools console cannot be used to interact with APM APIs.

For all APM APIs, you must use a request header. Supported headers are Authorization, kbn-xsrf, and Content-Type.

Authorization: ApiKey {credentials}

Kibana supports token-based authentication with the Elasticsearch API key service. The API key returned by the Elasticsearch create API key API can be used by sending a request with an Authorization header that has a value of ApiKey followed by the {credentials}, where {credentials} is the base64 encoding of id and api_key joined by a colon.

Alternatively, you can create a user and use their username and password to authenticate API access: -u $USER:$PASSWORD.

Whether using Authorization: ApiKey {credentials}, or -u $USER:$PASSWORD, users interacting with APM APIs must have sufficient privileges.

kbn-xsrf: true

By default, you must use kbn-xsrf for all API calls, except in the following scenarios:

Content-Type: application/json

Applicable only when you send a payload in the API request. Kibana API requests and responses use JSON. Typically, if you include the kbn-xsrf header, you must also include the Content-Type header.

Create or update annotation

Request

POST /api/apm/services/:serviceName/annotation

Request body

service

(required, object) Service identifying the configuration to create or update.

Properties of service

  • version

    (required, string) Version of service.

    environment

    (optional, string) Environment of service.

@timestamp

(required, string) The date and time of the annotation. Must be in ISO 8601 format.

message

(optional, string) The message displayed in the annotation. Defaults to service.version.

tags

(optional, array) Tags are used by the APM app to distinguish APM annotations from other annotations. Tags may have additional functionality in future releases. Defaults to [apm]. While you can add additional tags, you cannot remove the apm tag.

Example

The following example creates an annotation for a service named opbeans-java.

  1. curl -X POST \
  2. http://localhost:5601/api/apm/services/opbeans-java/annotation \
  3. -H 'Content-Type: application/json' \
  4. -H 'kbn-xsrf: true' \
  5. -H 'Authorization: Basic YhUlubWZhM0FDbnlQeE6WRtaW49FQmSGZ4RUWXdX' \
  6. -d '{
  7. "@timestamp": "2020-05-08T10:31:30.452Z",
  8. "service": {
  9. "version": "1.2"
  10. },
  11. "message": "Deployment 1.2"
  12. }'

Response body

  1. {
  2. "_index": "observability-annotations",
  3. "_id": "Lc9I93EBh6DbmkeV7nFX",
  4. "_version": 1,
  5. "_seq_no": 12,
  6. "_primary_term": 1,
  7. "found": true,
  8. "_source": {
  9. "message": "Deployment 1.2",
  10. "@timestamp": "2020-05-08T10:31:30.452Z",
  11. "service": {
  12. "version": "1.2",
  13. "name": "opbeans-java"
  14. },
  15. "tags": [
  16. "apm",
  17. "elastic.co",
  18. "customer"
  19. ],
  20. "annotation": {
  21. "type": "deployment"
  22. },
  23. "event": {
  24. "created": "2020-05-09T02:34:43.937Z"
  25. }
  26. }
  27. }

Most Popular