I'm trying to capture Azure Application Insights event in structured format using the below code in Pyspark (Azure Databricks) -
import requests
import json
appId = "..."
appKey = "..."
query = """traces | where timestamp > ago(1d) | order by timestamp"""
params = {"query": query}
headers = {'X-Api-Key': appKey}
url = f'https://api.applicationinsights.io/v1/apps/{appId}/query'
response = requests.get(url, headers=headers, params=params)
logs = json.loads(response.text)
json = json.dumps(logs)
jsonRDD = sc.parallelize([json])
df = spark.read.option('multiline', "true").json(jsonRDD)
display(df)
However, for some reason, this is returning json structure only. How to convert this into the structured or tabular format ?
Please help!