Azure-Samples / monitor-java-query-metrics-activitylogs

Getting metrics and activity logs for a resource.
https://docs.microsoft.com/java/azure
MIT License
3 stars 1 forks source link

Getting while trying to fetch the activity logs , Please help in resolving this issue. #2

Open yashaswi90 opened 2 years ago

yashaswi90 commented 2 years ago

2022-05-05 13:45:34.581 ERROR 16632 --- [onPool-worker-9] c.azure.identity.ClientSecretCredential : Azure Identity => ERROR in getToken() call for scopes [https://management.core.windows.net//.default]: java.util.Collections$SingletonList cannot be cast to java.lang.String 2022-05-05 13:45:34.583 ERROR 16632 --- [onPool-worker-9] c.a.c.implementation.AccessTokenCache : Failed to acquire a new access token.

java.lang.ClassCastException: java.util.Collections$SingletonList cannot be cast to java.lang.String

2022-05-05 13:45:34.580 ERROR 16632 --- [onPool-worker-9] c.m.a.m.ConfidentialClientApplication : [Correlation ID: cf2d211a-520c-456e-8a7b-749a4b15e73e] Execution of class com.microsoft.aad.msal4j.AcquireTokenByClientCredentialSupplier failed.

Please find below code which I am trying -

final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); TokenCredential tokenCredential = new DefaultAzureCredentialBuilder() .authorityHost("https://login.microsoftonline.com/common/oauth2/authorize") .build();

AzureResourceManager azureResourceManager = AzureResourceManager .configure() .withLogLevel(HttpLogDetailLevel.BASIC) .authenticate(tokenCredential, profile) .withDefaultSubscription();

PagedIterable logs = azureResourceManager.activityLogs().defineQuery() .startingFrom(OffsetDateTime.now().minusDays(24)) .endsBefore(OffsetDateTime.now()) .withAllPropertiesInResponse() .filterByResourceGroup("rgrp-name") .execute(); for (EventData event : logs) { System.out.println("\tCaller: " + event.caller()); System.out.println("\tCorrelationId: " + event.correlationId()); System.out.println("\tSubscriptionId: " + event.subscriptionId()); }

yashaswi90 commented 2 years ago

What is the issue in that code?