Forum Discussion

cdreeetz's avatar
cdreeetz
Copper Contributor
Nov 06, 2023

How to setup a Log Analytics Workspace in a Fabric Notebook

 

I am using azure-monitor-query to automate some logs we need but can't get the workspace to work in the notebook with service principal credentials.  The service principal has read access to the log analytics workspace.
credential = ClientSecretCredential(
    tenant_id= 'tenant_id', 
    client_id= "client_id", 
    client_secret= "client_secret")

client = LogsQueryClient(credential)

log_workspace_id = "workspace_id"

query = """AppRequests | take 5"""

start_time=datetime(2021, 7, 2, tzinfo=timezone.utc)
end_time=datetime(2021, 7, 4, tzinfo=timezone.utc)

try:
    response = client.query_workspace(
        workspace_id = log_workspace_id,
        query=query,
        timespan=(start_time, end_time)
        )
    if response.status == LogsQueryStatus.PARTIAL:
        error = response.partial_error
        data = response.partial_data
        print(error)
    elif response.status == LogsQueryStatus.SUCCESS:
        data = response.tables
    for table in data:
        df = pd.DataFrame(data=table.rows, columns=table.columns)
        print(df)
except HttpResponseError as err:
    print("something fatal happened")
    print(err)

 

something fatal happened (PathNotFoundError) The requested path does not exist Code: PathNotFoundError Message: The requested path does not exist

1 Reply

  • A PathNotFoundError typically indicates that an incorrect identifier has been provided for the Log Analytics workspace. When using the azure-monitor-query library, you must supply the Workspace ID (GUID) available in the Azure portal, rather than the resource name or full resource path. Additionally, confirm that the service principal has been granted the Monitoring Reader or Log Analytics Reader role at the workspace scope to ensure proper access.

Resources