Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
stevejgordon committed Apr 4, 2024
1 parent c589d9e commit 2e116c5
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 29 deletions.
6 changes: 4 additions & 2 deletions sample/WorkerServiceSample/Worker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

namespace WorkerServiceSample
{
public class Worker(IHttpClientFactory httpClientFactory) : BackgroundService
public class Worker : BackgroundService
{
private readonly IHttpClientFactory _httpClientFactory = httpClientFactory;
private readonly IHttpClientFactory _httpClientFactory;
private static readonly ActivitySource ActivitySource = new("MyActivitySource");

public Worker(IHttpClientFactory httpClientFactory) => _httpClientFactory = httpClientFactory;

protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static IServiceCollection AddElasticApmForAspNetCore(this IServiceCollect
{
var subs = subscribers.ToList();
subs.Add(new AspNetCoreDiagnosticSubscriber());
services.AddElasticApm([.. subs]);
services.AddElasticApm([..subs]);
}

return services;
Expand Down
6 changes: 4 additions & 2 deletions src/integrations/Elastic.Apm.Extensions.Hosting/ApmService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ namespace Elastic.Apm.NetCoreAll;
/// When registered into the DI container, this ensures that an instance of <see cref="IApmAgent"/> is
/// created by invoking the implementation factory.
/// </summary>
internal sealed class ApmService(IApmAgent agent) : IHostedService
internal sealed class ApmService : IHostedService
{
#pragma warning disable IDE0052 // Remove unread private members
private readonly IApmAgent _agent = agent;
private readonly IApmAgent _agent;
#pragma warning restore IDE0052 // Remove unread private members

public ApmService(IApmAgent agent) => _agent = agent;

public Task StartAsync(CancellationToken cancellationToken) => Task.CompletedTask;
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@

namespace Elastic.Apm.Extensions.Hosting;

internal sealed class NetCoreLogger(ILoggerFactory loggerFactory) : IApmLogger
internal sealed class NetCoreLogger : IApmLogger
{
private readonly ILogger _logger = loggerFactory?.CreateLogger("Elastic.Apm") ?? throw new ArgumentNullException(nameof(loggerFactory));
private readonly ILogger _logger;

public NetCoreLogger(ILoggerFactory loggerFactory) => _logger = loggerFactory?.CreateLogger("Elastic.Apm") ?? throw new ArgumentNullException(nameof(loggerFactory));

public bool IsEnabled(LogLevel level) => _logger.IsEnabled(Convert(level));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using Elastic.Apm;
using System;
using Elastic.Apm.Extensions.Hosting;
using Elastic.Apm;
using Elastic.Apm.Config;
using Elastic.Apm.DiagnosticSource;
using Elastic.Apm.Extensions.Hosting;
using Elastic.Apm.Extensions.Hosting.Config;
using Microsoft.Extensions.Hosting;
using Elastic.Apm.Extensions.Logging;
using Elastic.Apm.Logging;
using Elastic.Apm.DiagnosticSource;
using Elastic.Apm.NetCoreAll;
using Elastic.Apm.Report;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Elastic.Apm.Extensions.Logging;
using static Microsoft.Extensions.DependencyInjection.ServiceDescriptor;
using Microsoft.Extensions.DependencyInjection.Extensions;

namespace Microsoft.Extensions.DependencyInjection;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

namespace Elastic.Apm.Extensions.Logging
{
internal class ApmErrorLoggingProvider(IApmAgent apmAgent) : ILoggerProvider
internal class ApmErrorLoggingProvider : ILoggerProvider
{
private readonly IApmAgent _apmAgent = apmAgent;
private readonly IApmAgent _apmAgent;

public ApmErrorLoggingProvider(IApmAgent apmAgent) => _apmAgent = apmAgent;

public ILogger CreateLogger(string categoryName)
=> new ApmErrorLogger(_apmAgent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using Elastic.Apm.DiagnosticSource;
using Elastic.Apm.AspNetCore.DiagnosticListener;
using Elastic.Apm.Azure.CosmosDb;
using Elastic.Apm.Azure.ServiceBus;
using Elastic.Apm.Azure.Storage;
using Elastic.Apm.DiagnosticSource;
using Elastic.Apm.Elasticsearch;
using Elastic.Apm.EntityFrameworkCore;
using Elastic.Apm.GrpcClient;
Expand Down
2 changes: 1 addition & 1 deletion test/Elastic.Apm.Tests.Utilities/MockPayloadSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
namespace Elastic.Apm.Tests.Utilities
{
internal class MockPayloadSender : IPayloadSender
{
{
private static readonly JObject JsonSpanTypesData =
JObject.Parse(File.ReadAllText(Path.Combine(SolutionPaths.Root, "test/Elastic.Apm.Tests.Utilities/TestResources/json-specs/span_types.json")));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
namespace Elastic.Apm.Extensions.Hosting.Tests
{
public class HostingTests
{
private readonly ExtensionsTestHelper _extensionsTestHelper;
{
private readonly ExtensionsTestHelper _extensionsTestHelper;

public HostingTests(ITestOutputHelper output)
{
{
_extensionsTestHelper = new(output);
_extensionsTestHelper.TestSetup();
}

[Fact]
[Fact]
public async Task AddElasticApm_WhenEnabledIsNotConfigured() =>
await _extensionsTestHelper.ExecuteTestProcessAsync(null, false, false, false, false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@

namespace Elastic.Apm.Extensions.Tests.Shared;

public class ExtensionsTestHelper(ITestOutputHelper testOutput)
public class ExtensionsTestHelper
{
private readonly string _workingDirectory = Path.Combine(SolutionPaths.Root, "test", "integrations", "applications", "HostingTestApp");
private readonly ITestOutputHelper _testOutput = testOutput;
private readonly ITestOutputHelper _testOutput;

public ExtensionsTestHelper(ITestOutputHelper testOutput) => _testOutput = testOutput;

public void TestSetup()
{
Expand Down
12 changes: 6 additions & 6 deletions test/integrations/applications/HostingTestApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
// See the LICENSE file in the project root for more information

using Elastic.Apm;
using Elastic.Apm.Api;
using Elastic.Apm.DiagnosticSource;
using Test;
using Elastic.Apm.Extensions.Hosting;
using Elastic.Apm.Api;
using SampleConsoleNetCoreApp;
using Elastic.Apm.Tests.Utilities;
using Elastic.Apm.Report;
using Elastic.Apm.Tests.Utilities;
using SampleConsoleNetCoreApp;
using Test;

// This is an application used to test the Elastic.Apm.Extensions.Hosting and Elastic.Apm.Extensions.Logging
// packages. It is used by the Elastic.Apm.Extensions.Hosting.Tests project which starts this application
Expand All @@ -35,7 +35,7 @@
{
enabled = null;
}
else
else
{
if (!bool.TryParse(args[0], out var e))
throw new Exception("The first argument must be true, false or unset.");
Expand Down Expand Up @@ -190,7 +190,7 @@

if (payloadSender.Errors.SingleOrDefault(n => n.Log.Message == errorLogWithException &&
n.Log.StackTrace != null && n.Log.StackTrace.Count > 0) is null)
throw new Exception($"Expected one error log with exception.");
throw new Exception($"Expected one error log with exception.");
}

// Perform assertions based on the configuration
Expand Down

0 comments on commit 2e116c5

Please sign in to comment.