Skip to main content

IPython magic function for Dynatrace Query Language (DQL)

Project description

Dqlmagic

An IPython magic function allowing to use DQL in your notebooks.

Dynatrace Query Language (DQL) is a powerful tool to explore your data and discover patterns, identify anomalies and outliers, create statistical modeling, and more based on data stored in Dynatrace Grail storage.

Dqlmagic makes DQL queries available to be used in jupyter notebooks.

Available magic functions

%%dql or %dql

Executes a DQL query and returns the queried records as json array.

Example 1

Query in code-cell..

%%dql
fetch logs 
| limit 10

.. and use result in another code cell:

import pandas as pd

#put result into a dataframe
df = pd.DataFrame(_dql_result)
df.head()

Note: By default %%dql writes into _dql_result. You can optionally customize the target objects name to configure an alternative name like this:

%%dql my_result
fetch logs | limit 10

Example 2 - Inline Query

import pandas as pd

res = %dql fetch logs | limit 10
df = pd.DataFrame(res)
df.head()

%dql_raw and %%dql_raw

Same as %dql or %%dql, but returns instead of the result records the full API response json

%auth_grail <config_prefix>

Inline function connecting to the grail cluster.

Reads connection parameters from .env file:

dt_oauth_url="https://sso.dynatrace.com/sso/oauth2/token"

dt_oauth_clientid="<YOUR-CLIENT-ID>"
dt_oauth_clientsecret="<YOUR-CLIENT-SECRET>"
dt_oauth_scope="<YOUR-ACCESS-SCOPE>"

dt_tenant="<YOUR-TENANT-ID>"
grail_apiurl="https://<YOUR-TENANT-ID>.live.dynatrace.com/api/v2/dql/query"

The <config_prefix> is optional to be used if you have multiple configs stored in your .env file like e.g.

dt_config_prefix="DEV"

DEV_dt_oauth_url="https://sso.dynatrace.com/sso/oauth2/token"
DEV_dt_oauth_clientid="<YOUR-DEV-CLIENT-ID>"
DEV_dt_oauth_clientsecret="<YOUR-DEV-CLIENT-SECRET>"
DEV_dt_oauth_scope="<YOUR-DEV-ACCESS-SCOPE>"
DEV_dt_tenant="<YOUR-DEV-TENANT-ID>"
DEV_grail_apiurl="https://<YOUR-DEV-TENANT-ID>.apps.dynatracelabs.com/platform/storage/query/v1/"

PROD_dt_oauth_url="https://sso.dynatrace.com/sso/oauth2/token"
PROD_dt_oauth_clientid="<YOUR-PROD-CLIENT-ID>"
PROD_dt_oauth_clientsecret="<YOUR-PROD-CLIENT-SECRET>"
PROD_dt_oauth_scope="<YOUR-PROD-ACCESS-SCOPE>"
PROD_dt_tenant="<YOUR-PROD-TENANT-ID>"
PROD_grail_apiurl="https://<YOUR-PROD-TENANT-ID>.apps.dynatracelabs.com/platform/storage/query/v1/"

With the parameter dt_config_prefix, you set the default config prefix used, if %auth_grail parameter <config_prefix> is not provided.

For more details on how to setup API oauth clients in Dynatrace see Configure and manage account API OAuth clients

For more details on .env file see How to NOT embedded credential in Jupyter notebook or python-dotenv

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dqlmagic-1.3.2.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dqlmagic-1.3.2-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file dqlmagic-1.3.2.tar.gz.

File metadata

  • Download URL: dqlmagic-1.3.2.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for dqlmagic-1.3.2.tar.gz
Algorithm Hash digest
SHA256 48eb2ff82ed026204edb44661aebd59606477d6ee073e32b9624c3bb6a37a550
MD5 9725f6fe338001d99a3bffb04bf3eab9
BLAKE2b-256 0b53a27417bc7889162fcd5a0bc49a67e42ffaa6b29650d5c75aab516a1a78b0

See more details on using hashes here.

File details

Details for the file dqlmagic-1.3.2-py3-none-any.whl.

File metadata

  • Download URL: dqlmagic-1.3.2-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for dqlmagic-1.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 02f8f021678065d73e7f7b1178d9e09e29a3a291e3e9a270584c21712c40f8dd
MD5 a151b7e7805e0ac77fd881703d687bf3
BLAKE2b-256 434433fd9c3c5a10d38203972e6b1ab24e0713d736a2717133c14d8c7c5a84c6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page