/// <summary> /// The <see cref="GetUserDelegationKeyAsync"/> operation retrieves a /// key that can be used to delegate Active Directory authorization to /// shared access signatures created with <see cref="Sas.DataLakeSasBuilder"/>. /// </summary> /// <param name="startsOn"> /// Start time for the key's validity, with null indicating an /// immediate start. The time should be specified in UTC. /// </param> /// <param name="expiresOn"> /// Expiration of the key's validity. The time should be specified /// in UTC. /// </param> /// <param name="cancellationToken"> /// Optional <see cref="CancellationToken"/> to propagate /// notifications that the operation should be cancelled. /// </param> /// <returns> /// A <see cref="Response{UserDelegationKey}"/> describing /// the use delegation key. /// </returns> /// <remarks> /// A <see cref="RequestFailedException"/> will be thrown if /// a failure occurs. /// </remarks> public virtual async Task <Response <UserDelegationKey> > GetUserDelegationKeyAsync( DateTimeOffset?startsOn, DateTimeOffset expiresOn, CancellationToken cancellationToken = default) { DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(DataLakeServiceClient)}.{nameof(GetUserDelegationKey)}"); try { scope.Start(); Response <Blobs.Models.UserDelegationKey> response = await _blobServiceClient.GetUserDelegationKeyAsync( startsOn, expiresOn, cancellationToken) .ConfigureAwait(false); return(Response.FromValue( new UserDelegationKey(response.Value), response.GetRawResponse())); } catch (Exception ex) { scope.Failed(ex); throw; } finally { scope.Dispose(); } }
/// <summary> /// The <see cref="DeleteFileSystemAsync"/> operation marks the /// specified file system for deletion. The file system and any paths /// contained within it are later deleted during garbage collection. /// /// For more information, see /// <see href="https://docs.microsoft.com/rest/api/storageservices/delete-container"> /// Delete Container</see>. /// </summary> /// <param name="fileSystemName"> /// The name of the file system to delete. /// </param> /// <param name="conditions"> /// Optional <see cref="DataLakeRequestConditions"/> to add /// conditions on the deletion of this file system. /// </param> /// <param name="cancellationToken"> /// Optional <see cref="CancellationToken"/> to propagate /// notifications that the operation should be cancelled. /// </param> /// <returns> /// A <see cref="Response"/> if successful. /// </returns> /// <remarks> /// A <see cref="RequestFailedException"/> will be thrown if /// a failure occurs. /// </remarks> public virtual async Task <Response> DeleteFileSystemAsync( string fileSystemName, DataLakeRequestConditions conditions = default, CancellationToken cancellationToken = default) { DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(DataLakeServiceClient)}.{nameof(DeleteFileSystem)}"); try { scope.Start(); return(await GetFileSystemClient(fileSystemName) .DeleteAsync( conditions, cancellationToken) .ConfigureAwait(false)); } catch (Exception ex) { scope.Failed(ex); throw; } finally { scope.Dispose(); } }
/// <summary> /// The <see cref="CreateFileSystemAsync"/> operation creates a new /// file system under the specified account. If the file system with the /// same name already exists, the operation fails. /// /// For more information, see /// <see href="https://docs.microsoft.com/rest/api/storageservices/create-container"> /// Create Container</see>. /// </summary> /// <param name="fileSystemName"> /// The name of the file system to create. /// </param> /// <param name="publicAccessType"> /// Optionally specifies whether data in the file system may be accessed /// publicly and the level of access. <see cref="PublicAccessType.FileSystem"/> /// specifies full public read access for file system and path data. /// Clients can enumerate paths within the file system via anonymous /// request, but cannot enumerate file systems within the storage /// account. <see cref="PublicAccessType.Path"/> specifies public /// read access for paths. Path data within this file system can be /// read via anonymous request, but file system data is not available. /// Clients cannot enumerate paths within the file system via anonymous /// request. <see cref="PublicAccessType.None"/> specifies that the /// file system data is private to the account owner. /// </param> /// <param name="metadata"> /// Optional custom metadata to set for this file system. /// </param> /// <param name="cancellationToken"> /// Optional <see cref="CancellationToken"/> to propagate /// notifications that the operation should be cancelled. /// </param> /// <returns> /// A <see cref="Response{FileSystemClient}"/> referencing the /// newly created file system. /// </returns> /// <remarks> /// A <see cref="RequestFailedException"/> will be thrown if /// a failure occurs. /// </remarks> public virtual async Task <Response <DataLakeFileSystemClient> > CreateFileSystemAsync( string fileSystemName, PublicAccessType publicAccessType = PublicAccessType.None, Metadata metadata = default, CancellationToken cancellationToken = default) { DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(DataLakeServiceClient)}.{nameof(CreateFileSystem)}"); try { scope.Start(); DataLakeFileSystemClient fileSystem = GetFileSystemClient(fileSystemName); Response <FileSystemInfo> response = await fileSystem.CreateAsync(publicAccessType, metadata, cancellationToken).ConfigureAwait(false); return(Response.FromValue(fileSystem, response.GetRawResponse())); } catch (Exception ex) { scope.Failed(ex); throw; } finally { scope.Dispose(); } }
/// <summary> /// The <see cref="BreakAsync"/> operation breaks the path or /// file system's previously-acquired lease (if it exists). /// /// Once a lease is broken, it cannot be renewed. Any authorized /// request can break the lease; the request is not required to /// specify a matching lease ID. When a lease is broken, the lease /// break <paramref name="breakPeriod"/> is allowed to elapse, /// during which time no lease operation except /// <see cref="BreakAsync"/> and <see cref="ReleaseAsync"/> can be /// performed on the path or file system. When a lease is successfully /// broken, the response indicates the interval in seconds until a new /// lease can be acquired. /// /// A lease that has been broken can also be released. A client can /// immediately acquire a path or file system lease that has been /// released. /// /// For more information, see <see href="https://docs.microsoft.com/rest/api/storageservices/lease-container" />. /// </summary> /// <param name="breakPeriod"> /// Specifies the proposed duration the lease should continue before /// it is broken, in seconds, between 0 and 60. This break period is /// only used if it is shorter than the time remaining on the lease. /// If longer, the time remaining on the lease is used. A new lease /// will not be available before the break period has expired, but the /// lease may be held for longer than the break period. If this value /// is not provided, a fixed-duration lease breaks after the remaining /// lease period elapses, and an infinite lease breaks immediately. /// </param> /// <param name="conditions"> /// Optional <see cref="RequestConditions"/> to add /// conditions on acquiring a lease. /// </param> /// <param name="cancellationToken"> /// Optional <see cref="CancellationToken"/> to propagate /// notifications that the operation should be cancelled. /// </param> /// <returns> /// A <see cref="Response{Lease}"/> describing the broken lease. /// </returns> /// <remarks> /// A <see cref="RequestFailedException"/> will be thrown if /// a failure occurs. /// </remarks> public virtual async Task <Response <DataLakeLease> > BreakAsync( TimeSpan?breakPeriod = default, RequestConditions conditions = default, CancellationToken cancellationToken = default) { DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(DataLakeLeaseClient)}.{nameof(Break)}"); try { scope.Start(); Response <Blobs.Models.BlobLease> response = await _blobLeaseClient.BreakAsync( breakPeriod, conditions, cancellationToken).ConfigureAwait(false); return(Response.FromValue( response.Value.ToDataLakeLease(), response.GetRawResponse())); } catch (Exception ex) { scope.Failed(ex); throw; } finally { scope.Dispose(); } }
/// <summary> /// The <see cref="Change"/> operation changes the lease /// of an active lease. A change must include the current /// <see cref="LeaseId"/> and a new <paramref name="proposedId"/>. /// /// For more information, see <see href="https://docs.microsoft.com/rest/api/storageservices/lease-container" />. /// </summary> /// <param name="proposedId"> /// An optional proposed lease ID, in a GUID string format. A /// <see cref="RequestFailedException"/> will be thrown if the /// proposed lease ID is not in the correct format. /// </param> /// <param name="conditions"> /// Optional <see cref="RequestConditions"/> to add /// conditions on acquiring a lease. /// </param> /// <param name="cancellationToken"> /// Optional <see cref="CancellationToken"/> to propagate /// notifications that the operation should be cancelled. /// </param> /// <returns> /// A <see cref="Response{Lease}"/> describing the lease. /// </returns> /// <remarks> /// A <see cref="RequestFailedException"/> will be thrown if /// a failure occurs. /// </remarks> public virtual Response <DataLakeLease> Change( string proposedId, RequestConditions conditions = default, CancellationToken cancellationToken = default) { DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(DataLakeLeaseClient)}.{nameof(Change)}"); try { scope.Start(); Response <Blobs.Models.BlobLease> response = _blobLeaseClient.Change( proposedId, conditions, cancellationToken); return(Response.FromValue( response.Value.ToDataLakeLease(), response.GetRawResponse())); } catch (Exception ex) { scope.Failed(ex); throw; } finally { scope.Dispose(); } }
/// <summary> /// The <see cref="ReleaseAsync"/> operation releases the /// file system or path's previously-acquired lease. /// /// The lease may be released if the <see cref="LeaseId"/> /// matches that associated with the file system or path. Releasing the /// lease allows another client to immediately acquire the lease for the /// file system or path as soon as the release is complete. /// /// For more information, see <see href="https://docs.microsoft.com/rest/api/storageservices/lease-container" />. /// </summary> /// <param name="conditions"> /// Optional <see cref="RequestConditions"/> to add /// conditions on acquiring a lease. /// </param> /// <param name="cancellationToken"> /// Optional <see cref="CancellationToken"/> to propagate /// notifications that the operation should be cancelled. /// </param> /// <returns> /// A <see cref="Response{ReleasedObjectInfo}"/> describing the /// updated path or file system. /// </returns> /// <remarks> /// A <see cref="RequestFailedException"/> will be thrown if /// a failure occurs. /// </remarks> public virtual async Task <Response <ReleasedObjectInfo> > ReleaseAsync( RequestConditions conditions = default, CancellationToken cancellationToken = default) { DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(DataLakeLeaseClient)}.{nameof(Release)}"); try { scope.Start(); Response <Blobs.Models.ReleasedObjectInfo> response = await _blobLeaseClient.ReleaseAsync( conditions, cancellationToken) .ConfigureAwait(false); return(Response.FromValue( new ReleasedObjectInfo(response.Value.ETag, response.Value.LastModified), response.GetRawResponse())); } catch (Exception ex) { scope.Failed(ex); throw; } finally { scope.Dispose(); } }
/// <summary> /// The <see cref="RenewInternal"/> operation renews the /// shares's previously-acquired lease. This API does not /// support files. /// /// The lease can be renewed if the leaseId /// matches that associated with the share. Note that the /// lease may be renewed even if it has expired as long as the share /// has not been leased again since the expiration of that /// lease. When you renew a lease, the lease duration clock resets. /// /// </summary> /// <param name="async"> /// Whether to invoke the operation asynchronously. /// </param> /// <param name="cancellationToken"> /// Optional <see cref="CancellationToken"/> to propagate /// notifications that the operation should be cancelled. /// </param> /// <returns> /// A <see cref="Response{FileLease}"/> describing the lease. /// </returns> /// <remarks> /// A <see cref="RequestFailedException"/> will be thrown if /// a failure occurs. /// </remarks> private async Task <Response <ShareFileLease> > RenewInternal( bool async, CancellationToken cancellationToken) { EnsureClient(); using (ClientConfiguration.Pipeline.BeginLoggingScope(nameof(ShareLeaseClient))) { ClientConfiguration.Pipeline.LogMethodEnter( nameof(ShareLeaseClient), message: $"{nameof(Uri)}: {Uri}\n" + $"{nameof(LeaseId)}: {LeaseId}"); DiagnosticScope scope = ClientConfiguration.ClientDiagnostics.CreateScope($"{nameof(ShareLeaseClient)}.{nameof(Renew)}"); try { scope.Start(); if (FileClient != null) { throw new InvalidOperationException($"{nameof(Renew)} only supports Share Leases"); } else { ResponseWithHeaders <ShareRenewLeaseHeaders> response; if (async) { response = await ShareClient.ShareRestClient.RenewLeaseAsync( leaseId : LeaseId, cancellationToken : cancellationToken) .ConfigureAwait(false); } else { response = ShareClient.ShareRestClient.RenewLease( leaseId: LeaseId, cancellationToken: cancellationToken); } return(Response.FromValue( response.ToShareFileLease(), response.GetRawResponse())); } } catch (Exception ex) { ClientConfiguration.Pipeline.LogException(ex); scope.Failed(ex); throw; } finally { ClientConfiguration.Pipeline.LogMethodExit(nameof(ShareLeaseClient)); scope.Dispose(); } } }
private void FireScope(string method) { DiagnosticScopeFactory clientDiagnostics = new DiagnosticScopeFactory("Azure.Core.Tests", "random", true); string activityName = $"{typeof(InvalidDiagnosticScopeTestClient).Name}.{method}"; DiagnosticScope scope = clientDiagnostics.CreateScope(activityName); scope.Start(); scope.Dispose(); }
public virtual bool DuplicateScopeProperlyDisposed() { DiagnosticScope scope1 = CreateScope(nameof(DuplicateScopeProperlyDisposed)); scope1.Start(); scope1.Dispose(); using DiagnosticScope scope2 = CreateScope(nameof(DuplicateScopeProperlyDisposed)); scope2.Start(); return true; }
private void FireScope(string method) { ClientDiagnostics clientDiagnostics = new ClientDiagnostics(true); string activityName = $"{typeof(InvalidDiagnosticScopeTestClient).FullName}.{method}"; DiagnosticScope scope = clientDiagnostics.CreateScope(activityName); scope.Start(); scope.Dispose(); }
public void NoopsWhenDisabled() { ClientDiagnostics clientDiagnostics = new ClientDiagnostics("Azure.Clients", false); DiagnosticScope scope = clientDiagnostics.CreateScope(""); scope.AddAttribute("Attribute1", "Value1"); scope.AddAttribute("Attribute2", 2, i => i.ToString()); scope.Failed(new Exception()); scope.Dispose(); }
public void NoopsWhenDisabled() { DiagnosticScopeFactory clientDiagnostics = new DiagnosticScopeFactory("Azure.Clients", "Microsoft.Azure.Core.Cool.Tests", false); DiagnosticScope scope = clientDiagnostics.CreateScope(""); scope.AddAttribute("Attribute1", "Value1"); scope.AddAttribute("Attribute2", 2, i => i.ToString()); scope.Failed(new Exception()); scope.Dispose(); }
public void StartsActivitySourceActivity() { using var _ = SetAppConfigSwitch(); // Bug: there is no way to set activity type to W3C // https://github.com/dotnet/runtime/issues/43853 var oldDefault = Activity.DefaultIdFormat; Activity.DefaultIdFormat = ActivityIdFormat.W3C; try { using var activityListener = new TestActivitySourceListener("Azure.Clients.ClientName"); DiagnosticScopeFactory clientDiagnostics = new DiagnosticScopeFactory("Azure.Clients", "Microsoft.Azure.Core.Cool.Tests", true); DiagnosticScope scope = clientDiagnostics.CreateScope("ClientName.ActivityName"); scope.AddAttribute("Attribute1", "Value1"); scope.AddAttribute("Attribute2", 2, i => i.ToString()); scope.AddAttribute("Attribute3", 3); scope.AddLink("00-6e76af18746bae4eadc3581338bbe8b1-2899ebfdbdce904b-00"); scope.AddLink("00-6e76af18746bae4eadc3581338bbe8b2-2899ebfdbdce904b-00", new Dictionary <string, string>() { { "linkAttribute", "linkAttributeValue" } }); Assert.IsTrue(scope.IsEnabled); scope.Start(); scope.Dispose(); Assert.AreEqual(1, activityListener.Activities.Count); var activity = activityListener.Activities.Dequeue(); Assert.AreEqual("ClientName.ActivityName", activity.DisplayName); Assert.AreEqual("Value1", activity.TagObjects.Single(o => o.Key == "Attribute1").Value); Assert.AreEqual("2", activity.TagObjects.Single(o => o.Key == "Attribute2").Value); Assert.AreEqual("3", activity.TagObjects.Single(o => o.Key == "Attribute3").Value); var links = activity.Links.ToArray(); Assert.AreEqual(2, links.Length); Assert.AreEqual(ActivityContext.Parse("00-6e76af18746bae4eadc3581338bbe8b1-2899ebfdbdce904b-00", null), links[0].Context); Assert.AreEqual(ActivityContext.Parse("00-6e76af18746bae4eadc3581338bbe8b2-2899ebfdbdce904b-00", null), links[1].Context); Assert.AreEqual(ActivityIdFormat.W3C, activity.IdFormat); } finally { Activity.DefaultIdFormat = oldDefault; } }
public void StartActivityNoOpsWithoutSwitch() { using var activityListener = new TestActivitySourceListener("Azure.Clients.ClientName"); DiagnosticScopeFactory clientDiagnostics = new DiagnosticScopeFactory("Azure.Clients", "Microsoft.Azure.Core.Cool.Tests", true); DiagnosticScope scope = clientDiagnostics.CreateScope("ClientName.ActivityName"); scope.Start(); scope.Dispose(); Assert.AreEqual(0, activityListener.Activities.Count); }
/// <summary> /// Sets the properties of the queue service. /// /// For more information, see /// <see href="https://docs.microsoft.com/rest/api/storageservices/set-queue-service-properties"> /// Set Queue Service Properties</see>. /// </summary> /// <param name="properties"> /// <see cref="QueueServiceProperties"/> /// </param> /// <param name="async"> /// Whether to invoke the operation asynchronously. /// </param> /// <param name="cancellationToken"> /// <see cref="CancellationToken"/> /// </param> /// <returns> /// <see cref="Response"/> /// </returns> private async Task <Response> SetPropertiesInternal( QueueServiceProperties properties, bool async, CancellationToken cancellationToken) { using (ClientConfiguration.Pipeline.BeginLoggingScope(nameof(QueueServiceClient))) { ClientConfiguration.Pipeline.LogMethodEnter( nameof(QueueServiceClient), message: $"{nameof(Uri)}: {Uri}\n" + $"{nameof(properties)}: {properties}"); DiagnosticScope scope = ClientConfiguration.ClientDiagnostics.CreateScope($"{nameof(QueueServiceClient)}.{nameof(SetProperties)}"); try { ResponseWithHeaders <ServiceSetPropertiesHeaders> response; scope.Start(); if (async) { response = await _serviceRestClient.SetPropertiesAsync( storageServiceProperties : properties, cancellationToken : cancellationToken) .ConfigureAwait(false); } else { response = _serviceRestClient.SetProperties( storageServiceProperties: properties, cancellationToken: cancellationToken); } return(response.GetRawResponse()); } catch (Exception ex) { ClientConfiguration.Pipeline.LogException(ex); scope.Failed(ex); throw; } finally { ClientConfiguration.Pipeline.LogMethodExit(nameof(QueueServiceClient)); scope.Dispose(); } } }
public void NestedClientActivitiesNotSuppressed(int kind) { using var testListener = new TestDiagnosticListener("Azure.Clients"); DiagnosticScopeFactory clientDiagnostics = new DiagnosticScopeFactory("Azure.Clients", "Microsoft.Azure.Core.Cool.Tests", true, false); using DiagnosticScope scope = clientDiagnostics.CreateScope("ClientName.ActivityName", (DiagnosticScope.ActivityKind)kind); scope.Start(); DiagnosticScope nestedScope = clientDiagnostics.CreateScope("ClientName.NestedActivityName", (DiagnosticScope.ActivityKind)kind); nestedScope.Start(); Assert.IsTrue(nestedScope.IsEnabled); Assert.AreEqual("ClientName.NestedActivityName", Activity.Current.OperationName); nestedScope.Dispose(); Assert.AreEqual("ClientName.ActivityName", Activity.Current.OperationName); }
public void SequentialActivitiesNoSuppression() { using var activityListener2 = new TestDiagnosticListener("Azure.Clients"); DiagnosticScopeFactory clientDiagnostics = new DiagnosticScopeFactory("Azure.Clients", "Microsoft.Azure.Core.Cool.Tests", true, false); DiagnosticScope scope = clientDiagnostics.CreateScope("ClientName.ActivityName"); scope.Start(); scope.Dispose(); DiagnosticScope nextScope = clientDiagnostics.CreateScope("ClientName.ActivityName"); nextScope.Start(); Assert.IsTrue(nextScope.IsEnabled); Assert.AreEqual("ClientName.ActivityName", Activity.Current.OperationName); nextScope.Dispose(); Assert.IsNull(Activity.Current); }
public void StartActivitySourceActivityIgnoresInvalidLinkParent() { using var _ = SetAppConfigSwitch(); using var activityListener = new TestActivitySourceListener("Azure.Clients.ClientName"); DiagnosticScopeFactory clientDiagnostics = new DiagnosticScopeFactory("Azure.Clients", "Microsoft.Azure.Core.Cool.Tests", true); DiagnosticScope scope = clientDiagnostics.CreateScope("ClientName.ActivityName"); scope.AddLink("test"); scope.Start(); scope.Dispose(); Assert.AreEqual(0, activityListener.Activities.Single().Links.Count()); }
public void CanSetActivitySourceAndDiagnosticSourceActivitiesTogether() { using var _ = SetAppConfigSwitch(); using var testListener = new TestDiagnosticListener("Azure.Clients"); using var activityListener = new TestActivitySourceListener("Azure.Clients.ClientName"); DiagnosticScopeFactory clientDiagnostics = new DiagnosticScopeFactory("Azure.Clients", "Microsoft.Azure.Core.Cool.Tests", true); DiagnosticScope scope = clientDiagnostics.CreateScope("ClientName.ActivityName"); scope.Start(); (string Key, object Value, DiagnosticListener)startEvent = testListener.Events.Dequeue(); Activity activityAfterStart = Activity.Current; scope.AddAttribute("Attribute1", "Value1"); scope.AddAttribute("Attribute2", 2, i => i.ToString()); scope.AddAttribute("Attribute3", 3); scope.Dispose(); (string Key, object Value, DiagnosticListener)stopEvent = testListener.Events.Dequeue(); Assert.AreEqual(1, activityListener.Activities.Count); var activitySourceActivity = activityListener.Activities.Dequeue(); Assert.AreEqual("Value1", activitySourceActivity.TagObjects.Single(o => o.Key == "Attribute1").Value); Assert.AreEqual("2", activitySourceActivity.TagObjects.Single(o => o.Key == "Attribute2").Value); Assert.AreEqual("3", activitySourceActivity.TagObjects.Single(o => o.Key == "Attribute3").Value); Assert.Null(Activity.Current); Assert.AreEqual("ClientName.ActivityName.Start", startEvent.Key); Assert.AreEqual("ClientName.ActivityName.Stop", stopEvent.Key); var diagnosticSourceActivity = (Activity)startEvent.Value; Assert.AreEqual(ActivityIdFormat.W3C, diagnosticSourceActivity.IdFormat); CollectionAssert.Contains(diagnosticSourceActivity.Tags, new KeyValuePair <string, string>("Attribute1", "Value1")); CollectionAssert.Contains(diagnosticSourceActivity.Tags, new KeyValuePair <string, string>("Attribute2", "2")); CollectionAssert.Contains(diagnosticSourceActivity.Tags, new KeyValuePair <string, string>("Attribute3", "3")); Assert.AreEqual(activityAfterStart, diagnosticSourceActivity); }
public void AddLinkCallsPassesLinksAsPartOfStartPayload() { using var testListener = new TestDiagnosticListener("Azure.Clients"); DiagnosticScopeFactory clientDiagnostics = new DiagnosticScopeFactory("Azure.Clients", "Microsoft.Azure.Core.Cool.Tests", true); DiagnosticScope scope = clientDiagnostics.CreateScope("ActivityName"); scope.AddLink("00-6e76af18746bae4eadc3581338bbe8b1-2899ebfdbdce904b-00", "foo=bar"); scope.AddLink("00-6e76af18746bae4eadc3581338bbe8b2-2899ebfdbdce904b-00", null); scope.Start(); (string Key, object Value, DiagnosticListener)startEvent = testListener.Events.Dequeue(); Activity activity = Activity.Current; scope.Dispose(); (string Key, object Value, DiagnosticListener)stopEvent = testListener.Events.Dequeue(); var isEnabledCall = testListener.IsEnabledCalls.Dequeue(); Assert.NotNull(activity); Assert.Null(Activity.Current); Assert.AreEqual("ActivityName.Start", startEvent.Key); Assert.AreEqual("ActivityName.Stop", stopEvent.Key); Assert.AreEqual("ActivityName", isEnabledCall.Name); var activities = (IEnumerable <Activity>)startEvent.Value.GetType().GetTypeInfo().GetDeclaredProperty("Links").GetValue(startEvent.Value); Activity[] activitiesArray = activities.ToArray(); Assert.AreEqual(activitiesArray.Length, 2); Activity linkedActivity1 = activitiesArray[0]; Activity linkedActivity2 = activitiesArray[1]; Assert.AreEqual(ActivityIdFormat.W3C, linkedActivity1.IdFormat); Assert.AreEqual("00-6e76af18746bae4eadc3581338bbe8b1-2899ebfdbdce904b-00", linkedActivity1.ParentId); Assert.AreEqual("foo=bar", linkedActivity1.TraceStateString); Assert.AreEqual(ActivityIdFormat.W3C, linkedActivity2.IdFormat); Assert.AreEqual("00-6e76af18746bae4eadc3581338bbe8b2-2899ebfdbdce904b-00", linkedActivity2.ParentId); Assert.Null(linkedActivity2.TraceStateString); Assert.AreEqual(0, testListener.Events.Count); }
public void NestedClientActivitiesSuppressionByDefault() { using var _ = SetAppConfigSwitch(); using var activityListener = new TestActivitySourceListener("Azure.Clients.ClientName"); DiagnosticScopeFactory clientDiagnostics = new DiagnosticScopeFactory("Azure.Clients", "Microsoft.Azure.Core.Cool.Tests", true); using DiagnosticScope scope = clientDiagnostics.CreateScope("ClientName.ActivityName", DiagnosticScope.ActivityKind.Client); scope.Start(); DiagnosticScope nestedScope = clientDiagnostics.CreateScope("ClientName.NestedActivityName", DiagnosticScope.ActivityKind.Internal); nestedScope.Start(); Assert.IsFalse(nestedScope.IsEnabled); Assert.AreEqual("ClientName.ActivityName", Activity.Current.OperationName); nestedScope.Dispose(); Assert.AreEqual("ClientName.ActivityName", Activity.Current.OperationName); }
public void ActivityDurationIsNotZeroWhenStoping() { TimeSpan? duration = null; using var testListener = new TestDiagnosticListener("Azure.Clients"); testListener.EventCallback = _ => { duration = Activity.Current?.Duration; }; DiagnosticScopeFactory clientDiagnostics = new DiagnosticScopeFactory("Azure.Clients", "Microsoft.Azure.Core.Cool.Tests", true, false); DiagnosticScope scope = clientDiagnostics.CreateScope("ActivityName"); scope.Start(); Thread.Sleep(50); scope.Dispose(); Assert.True(duration > TimeSpan.Zero); }
/// <summary> /// The SetBlobsAccessTierAsync operation sets the tier on blobs. The /// operation is allowed on block blobs in a blob storage or general /// purpose v2 account. /// </summary> /// <param name="blobUris"> /// URIs of the blobs to set the tiers of. /// </param> /// <param name="accessTier"> /// Indicates the tier to be set on the blobs. /// </param> /// <param name="rehydratePriority"> /// Optional <see cref="RehydratePriority"/> /// Indicates the priority with which to rehydrate an archived blob. /// </param> /// <param name="async"> /// Whether to invoke the operation asynchronously. /// </param> /// <param name="cancellationToken"> /// Optional <see cref="CancellationToken"/> to propagate notifications /// that the operation should be cancelled. /// </param> /// <returns> /// The <see cref="Response"/>s for the individual Set Tier operations. /// </returns> /// <remarks> /// A <see cref="RequestFailedException"/> will be thrown if /// a failure to submit the batch occurs. Individual sub-operation /// failures will be wrapped in an <see cref="AggregateException"/>. /// </remarks> internal async Task <Response[]> SetBlobsAccessTierInteral( IEnumerable <Uri> blobUris, AccessTier accessTier, RehydratePriority?rehydratePriority, bool async, CancellationToken cancellationToken) { DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(BlobBatchClient)}.{nameof(SetBlobsAccessTier)}"); try { scope.Start(); blobUris = blobUris ?? throw new ArgumentNullException(nameof(blobUris)); var responses = new List <Response>(); // Create the batch BlobBatch batch = CreateBatch(); foreach (Uri uri in blobUris) { responses.Add(batch.SetBlobAccessTier(uri, accessTier, rehydratePriority)); } // Submit the batch await SubmitBatchInternal( batch, true, async, cancellationToken) .ConfigureAwait(false); return(responses.ToArray()); } catch (Exception ex) { scope.Failed(ex); throw; } finally { scope.Dispose(); } }
public void NestedActivitiesNoSuppressionDifferentSourcesServerClient() { using var testListener = new TestDiagnosticListener("Azure.Clients"); DiagnosticScopeFactory clientDiagnostics = new DiagnosticScopeFactory("Azure.Clients", "Microsoft.Azure.Core.Cool.Tests", true, false); ; DiagnosticScope scope = clientDiagnostics.CreateScope("ClientName.ActivityName", DiagnosticScope.ActivityKind.Server); scope.Start(); using var activityListener2 = new TestDiagnosticListener("Azure.Clients2"); DiagnosticScopeFactory clientDiagnostics2 = new DiagnosticScopeFactory("Azure.Clients2", "Microsoft.Azure.Core.Cool.Tests", true, false); DiagnosticScope nestedScope = clientDiagnostics2.CreateScope("ClientName.NestedActivityName"); nestedScope.Start(); Assert.IsTrue(nestedScope.IsEnabled); Assert.AreEqual("ClientName.NestedActivityName", Activity.Current.OperationName); nestedScope.Dispose(); Assert.AreEqual("ClientName.ActivityName", Activity.Current.OperationName); scope.Dispose(); }
public void ActivityStartTimeCanBeSet() { DateTime?actualStartTimeUtc = null; using var testListener = new TestDiagnosticListener("Azure.Clients"); testListener.EventCallback = _ => { actualStartTimeUtc = Activity.Current?.StartTimeUtc; }; DiagnosticScopeFactory clientDiagnostics = new DiagnosticScopeFactory("Azure.Clients", "Microsoft.Azure.Core.Cool.Tests", true, false); DiagnosticScope scope = clientDiagnostics.CreateScope("ActivityName"); DateTime expectedStartTimeUtc = DateTime.UtcNow - TimeSpan.FromSeconds(10); scope.SetStartTime(expectedStartTimeUtc); scope.Start(); scope.Dispose(); Assert.AreEqual(expectedStartTimeUtc, actualStartTimeUtc); }
public void CanSetActivitySourceAttributesAfterStarting() { using var _ = SetAppConfigSwitch(); using var activityListener = new TestActivitySourceListener("Azure.Clients.ClientName"); DiagnosticScopeFactory clientDiagnostics = new DiagnosticScopeFactory("Azure.Clients", "Microsoft.Azure.Core.Cool.Tests", true); DiagnosticScope scope = clientDiagnostics.CreateScope("ClientName.ActivityName"); scope.Start(); scope.AddAttribute("name", "value"); scope.Dispose(); Assert.AreEqual(1, activityListener.Activities.Count); var activity = activityListener.Activities.Dequeue(); Assert.AreEqual("value", activity.TagObjects.Single(o => o.Key == "name").Value); }
/// <summary> /// The DeleteBlobsAsync operation marks the specified blobs for /// deletion. The blobs are later deleted during garbage collection /// which could take several minutes. /// All of the deletions are sent as a single batched request. /// </summary> /// <param name="blobUris">URIs of the blobs to delete.</param> /// <param name="snapshotsOption"> /// Specifies options for deleting blob snapshots. /// </param> /// <param name="async"> /// Whether to invoke the operation asynchronously. /// </param> /// <param name="cancellationToken"> /// Optional <see cref="CancellationToken"/> to propagate notifications /// that the operation should be cancelled. /// </param> /// <returns> /// The <see cref="Response"/>s for the individual Delete operations. /// </returns> /// <remarks> /// A <see cref="RequestFailedException"/> will be thrown if /// a failure to submit the batch occurs. Individual sub-operation /// failures will be wrapped in an <see cref="AggregateException"/>. /// </remarks> internal async Task <Response[]> DeleteBlobsInteral( IEnumerable <Uri> blobUris, DeleteSnapshotsOption snapshotsOption, bool async, CancellationToken cancellationToken) { DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(BlobBatchClient)}.{nameof(DeleteBlobs)}"); try { scope.Start(); blobUris = blobUris ?? throw new ArgumentNullException(nameof(blobUris)); var responses = new List <Response>(); // Create the batch BlobBatch batch = CreateBatch(); foreach (Uri uri in blobUris) { responses.Add(batch.DeleteBlob(uri, snapshotsOption)); } // Submit the batch await SubmitBatchInternal( batch, true, async, cancellationToken) .ConfigureAwait(false); return(responses.ToArray()); } catch (Exception ex) { scope.Failed(ex); throw; } finally { scope.Dispose(); } }
public void AddLinkCallsPassesLinksAsPartOfStartPayload() { using var testListener = new TestDiagnosticListener("Azure.Clients"); DiagnosticScopeFactory clientDiagnostics = new DiagnosticScopeFactory("Azure.Clients", "Microsoft.Azure.Core.Cool.Tests", true); DiagnosticScope scope = clientDiagnostics.CreateScope("ActivityName"); scope.AddLink("id"); scope.AddLink("id2"); scope.Start(); (string Key, object Value, DiagnosticListener)startEvent = testListener.Events.Dequeue(); Activity activity = Activity.Current; scope.Dispose(); (string Key, object Value, DiagnosticListener)stopEvent = testListener.Events.Dequeue(); Assert.Null(Activity.Current); Assert.AreEqual("ActivityName.Start", startEvent.Key); Assert.AreEqual("ActivityName.Stop", stopEvent.Key); var activities = (IEnumerable <Activity>)startEvent.Value.GetType().GetTypeInfo().GetDeclaredProperty("Links").GetValue(startEvent.Value); Activity[] activitiesArray = activities.ToArray(); Assert.AreEqual(activitiesArray.Length, 2); Activity linkedActivity1 = activitiesArray[0]; Activity linkedActivity2 = activitiesArray[1]; Assert.AreEqual(ActivityIdFormat.W3C, linkedActivity1.IdFormat); Assert.AreEqual("id", linkedActivity1.ParentId); Assert.AreEqual(ActivityIdFormat.W3C, linkedActivity2.IdFormat); Assert.AreEqual("id2", linkedActivity2.ParentId); Assert.AreEqual(0, testListener.Events.Count); }
public void ResourceNameIsOptional() { using var testListener = new TestDiagnosticListener("Azure.Clients"); DiagnosticScopeFactory clientDiagnostics = new DiagnosticScopeFactory("Azure.Clients", null, true, false); DiagnosticScope scope = clientDiagnostics.CreateScope("ActivityName"); scope.Start(); (string Key, object Value, DiagnosticListener) startEvent = testListener.Events.Dequeue(); Activity activity = Activity.Current; scope.Dispose(); (string Key, object Value, DiagnosticListener) stopEvent = testListener.Events.Dequeue(); Assert.Null(Activity.Current); Assert.AreEqual("ActivityName.Start", startEvent.Key); Assert.AreEqual("ActivityName.Stop", stopEvent.Key); Assert.AreEqual(ActivityIdFormat.W3C, activity.IdFormat); }
public void NestedActivitiesOuterSampledOut() { using var _ = SetAppConfigSwitch(); using var activityListener = new TestActivitySourceListener("Azure.Clients.ClientName"); DiagnosticScopeFactory clientDiagnostics = new DiagnosticScopeFactory("Azure.Clients", "Microsoft.Azure.Core.Cool.Tests", true, true); DiagnosticScope scope = clientDiagnostics.CreateScope("ClientName.ActivityName"); scope.AddAttribute("sampled-out", true); scope.Start(); Assert.IsNull(Activity.Current); using var activityListener2 = new TestActivitySourceListener("Azure.Clients2.ClientName"); DiagnosticScopeFactory clientDiagnostics2 = new DiagnosticScopeFactory("Azure.Clients2", "Microsoft.Azure.Core.Cool.Tests", true, true); DiagnosticScope nestedScope = clientDiagnostics2.CreateScope("ClientName.NestedActivityName"); nestedScope.Start(); Assert.IsTrue(nestedScope.IsEnabled); Assert.AreEqual("ClientName.NestedActivityName", Activity.Current.OperationName); nestedScope.Dispose(); Assert.IsNull(Activity.Current); }