API

API Tokens

In order to use the REST API, you need to create an API token and assign permissions to it. API tokens are managed only by the account owner role, who can create multiple API tokens with varying permissions.

API token management can found in Settings → Access Control → API Tokens.

REST API

The Instana REST API HTTP endpoints allow data retrieval, like traces and metrics, as well as configuration, like service extraction and users.

The API documentation is available via Postman: https://documenter.getpostman.com/view/1527374/RWEiLJXR

Python REST API Client

To better utilize the REST API outlined above, we have put together a Python REST API Client for simple access to your data from Python.

To use the this client, you must have the Python Sensor installed (pip install instana) and optionally the following environment variables set:

INSTANA_API_TOKEN=<MY_API_TOKEN>
INSTANA_BASE_URL=https://<dashboard-url>

You can get an API token by navigating in your dashboard to Settings -> Access Control -> API Tokens. See also the section above.

Example Usage:

from instana.api import APIClient
c = APIClient(base_url="https://<dashboard-url>", api_token='MY_API_TOKEN')

# Or, alternatively if you have the environment variables set
# c = APIClient()

# Retrieve the current application view
av = c.application_view()
av.json()

# Retrieve the current infrastructure view
iv = c.infrastructure_view()

# Retrieve snapshots results from a query
ss = c.snapshots("entity.selfType:webService entity.service.name:\"pwpush.com\"")

# Get all EUM apps
ea = c.eum_apps()

# Get all Service Extraction Configs
sec = c.service_extraction_configs()

For more information, see the Python repository.

Event SDK REST Web Service

Using the Event SDK REST Web Service, it is possible to integrate custom health checks and other event sources into Instana. Each one running the Instana Agent can be used to feed in manual events. The agent has an endpoint which listens on http://localhost:42699/com.instana.plugin.generic.event and accepts the following JSON via a POST request:

{
  "title": <string>,
  "text": <string>,
  "severity": <integer> , -1, 5 or 10
  "timestamp": <integer>, timestamp in milliseconds from epoch
  "duration": <integer>, duration in milliseconds
}

Title and text are used for display purposes.

Severity is an optional integer of -1, 5 and 10. A value of -1 or EMPTY will generate a Change. A value of 5 will generate a warning Issue, and a value of 10 will generate a critical Issue.

When absent, the event is treated as a change without severity. Timestamp is the timestamp of the event, but it is optional, in which case the current time is used. Duration can be used to mark a timespan for the event. It also is optional, in which case the event will be marked as “instant” rather than “from-to.”

The endpoint also accepts a batch of events, which then need to be given as an array:

[
  {
    // event as above
  },
  {
    // event as above
  }
]

Ruby Example

duration = (Time.now.to_f * 1000).floor - deploy_start_time_in_ms
payload = {}
payload[:title] = 'Deployed MyApp'
payload[:text] = 'pglombardo deployed MyApp@revision'
payload[:duration] = duration

uri = URI('http://localhost:42699/com.instana.plugin.generic.event')
req = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
req.body = payload.to_json
Net::HTTP.start(uri.hostname, uri.port) do |http|
  http.request(req)
end

Curl Example

curl -XPOST http://localhost:42699/com.instana.plugin.generic.event -H "Content-Type: application/json" -d '{"title":"Custom API Events ", "text": "Failure Redeploying Service Duration", "duration": 5000, "severity": -1}'

PowerShell Example

For Powershell you can either use the standard Cmdlets Invoke-WebRequest or Invoke-RestMethod. The parameters to be provided are basically the same.

Invoke-RestMethod
	-Uri http://localhost:42699/com.instana.plugin.generic.event
	-Method POST
	-Body '{"title":"PowerShell Event ", "text": "You used PowerShell to create this event!", "duration": 5000, "severity": -1}'
Invoke-WebRequest
  -Uri http://localhost:42699/com.instana.plugin.generic.event
  -Method Post
  -Body '{"title":"PowerShell Event ", "text": "You used PowerShell to create this event!", "duration": 5000, "severity": -1}'

Ansible Integration

Learn more about our Ansible event integration.

Mina Integration

Learn more about our Mina event integration.