Skip to content

Commit

Permalink
Initial commit MassTransit
Browse files Browse the repository at this point in the history
  • Loading branch information
glucaci committed Mar 5, 2021
1 parent 1e64ff1 commit 2791f65
Show file tree
Hide file tree
Showing 19 changed files with 607 additions and 51 deletions.
10 changes: 10 additions & 0 deletions src/Dependencies.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project>

<PropertyGroup>
<ElasticApmVersion>1.8.0</ElasticApmVersion>
<HotChocolateVersion>11.0.0</HotChocolateVersion>
<MassTransitVersion>7.1.0</MassTransitVersion>
<SystemDiagnosticSourceVersion>4.7.0</SystemDiagnosticSourceVersion>
</PropertyGroup>

</Project>
49 changes: 42 additions & 7 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,12 +1,47 @@
<Project>
<Import Project="$([MSBuild]::GetPathOfFileAbove('Dependencies.props', '$(MSBuildThisFileDirectory)'))" />
<Import Project="$([MSBuild]::GetPathOfFileAbove('Nullable.props', '$(MSBuildThisFileDirectory)'))" />

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<PropertyGroup>
<LangVersion>latest</LangVersion>
<Version Condition="$(Version) == ''">0.0.0</Version>
<Nullable>enable</Nullable>
<WarningsAsErrors>nullable</WarningsAsErrors>
</PropertyGroup>

<PropertyGroup>
<CCSourceDirectory>$(MSBuildThisFileDirectory.TrimEnd('\').TrimEnd('/'))</CCSourceDirectory>
<CCSettingsProps>$([System.IO.Path]::Combine($(CCSourceDirectory), 'Settings.props'))</CCSettingsProps>
<CCVersionProps>$([System.IO.Path]::Combine($(CCSourceDirectory), 'Version.props'))</CCVersionProps>
<CCPackageProps>$([System.IO.Path]::Combine($(CCSourceDirectory), 'Package.props'))</CCPackageProps>
<Product>Elastic APM .NET Agent Extensions</Product>
<Authors>Swiss Life authors and contributors</Authors>
<Company>Swiss Life</Company>
<Copyright>Copyright © $(Company) $([System.DateTime]::Now.Year)</Copyright>
<PackageLicenseUrl>https://github.com/SwissLife-OSS/elastic-apm-extensions/blob/master/LICENSE</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/SwissLife-OSS/elastic-apm-extensions</PackageProjectUrl>
<PackageReleaseNotes>Release notes: https://github.com/SwissLife-OSS/elastic-apm-extensions/releases/$(Version)</PackageReleaseNotes>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageIconUrl>https://github.com/SwissLife-OSS/elastic-apm-extensions/raw/master/logo.png</PackageIconUrl>
<IsPackable>false</IsPackable>
</PropertyGroup>

<Import Project="$(CCSettingsProps)" Condition="Exists('$(CCSettingsProps)')"/>
<Import Project="$(CCVersionProps)" Condition="Exists('$(CCVersionProps)')"/>
<Import Project="$(CCPackageProps)" Condition="Exists('$(CCPackageProps)')"/>
<PropertyGroup>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<RepositoryUrl>https://github.com/SwissLife-OSS/elastic-apm-extensions.git</RepositoryUrl>
<RepositoryType>GitHub</RepositoryType>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>

<PropertyGroup>
<DebugType>portable</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/>
</ItemGroup>

</Project>
6 changes: 0 additions & 6 deletions src/Directory.Build.targets

This file was deleted.

51 changes: 51 additions & 0 deletions src/Elastic.Apm.Extensions.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30907.101
MinimumVisualStudioVersion = 15.0.26124.0
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Elastic.Apm.GraphQL.HotChocolate", "Elastic.Apm.GraphQL.HotChocolate\Elastic.Apm.GraphQL.HotChocolate.csproj", "{FF6547C4-550A-4F3C-88AB-7DE2C88947C5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Elastic.Apm.Messaging.MassTransit", "Elastic.Apm.Messaging.MassTransit\Elastic.Apm.Messaging.MassTransit.csproj", "{9F5A0818-9E19-4B24-B955-4DBFE871271F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{FF6547C4-550A-4F3C-88AB-7DE2C88947C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FF6547C4-550A-4F3C-88AB-7DE2C88947C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FF6547C4-550A-4F3C-88AB-7DE2C88947C5}.Debug|x64.ActiveCfg = Debug|Any CPU
{FF6547C4-550A-4F3C-88AB-7DE2C88947C5}.Debug|x64.Build.0 = Debug|Any CPU
{FF6547C4-550A-4F3C-88AB-7DE2C88947C5}.Debug|x86.ActiveCfg = Debug|Any CPU
{FF6547C4-550A-4F3C-88AB-7DE2C88947C5}.Debug|x86.Build.0 = Debug|Any CPU
{FF6547C4-550A-4F3C-88AB-7DE2C88947C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FF6547C4-550A-4F3C-88AB-7DE2C88947C5}.Release|Any CPU.Build.0 = Release|Any CPU
{FF6547C4-550A-4F3C-88AB-7DE2C88947C5}.Release|x64.ActiveCfg = Release|Any CPU
{FF6547C4-550A-4F3C-88AB-7DE2C88947C5}.Release|x64.Build.0 = Release|Any CPU
{FF6547C4-550A-4F3C-88AB-7DE2C88947C5}.Release|x86.ActiveCfg = Release|Any CPU
{FF6547C4-550A-4F3C-88AB-7DE2C88947C5}.Release|x86.Build.0 = Release|Any CPU
{9F5A0818-9E19-4B24-B955-4DBFE871271F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9F5A0818-9E19-4B24-B955-4DBFE871271F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9F5A0818-9E19-4B24-B955-4DBFE871271F}.Debug|x64.ActiveCfg = Debug|Any CPU
{9F5A0818-9E19-4B24-B955-4DBFE871271F}.Debug|x64.Build.0 = Debug|Any CPU
{9F5A0818-9E19-4B24-B955-4DBFE871271F}.Debug|x86.ActiveCfg = Debug|Any CPU
{9F5A0818-9E19-4B24-B955-4DBFE871271F}.Debug|x86.Build.0 = Debug|Any CPU
{9F5A0818-9E19-4B24-B955-4DBFE871271F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9F5A0818-9E19-4B24-B955-4DBFE871271F}.Release|Any CPU.Build.0 = Release|Any CPU
{9F5A0818-9E19-4B24-B955-4DBFE871271F}.Release|x64.ActiveCfg = Release|Any CPU
{9F5A0818-9E19-4B24-B955-4DBFE871271F}.Release|x64.Build.0 = Release|Any CPU
{9F5A0818-9E19-4B24-B955-4DBFE871271F}.Release|x86.ActiveCfg = Release|Any CPU
{9F5A0818-9E19-4B24-B955-4DBFE871271F}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F5A91904-BC2B-4796-8836-2FB19ADC7015}
EndGlobalSection
EndGlobal
8 changes: 8 additions & 0 deletions src/Elastic.Apm.GraphQL.HotChocolate/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project>
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)..\'))" />

<PropertyGroup>
<PackageTags>apm monitoring elastic elasticapm analytics graphql hotchocolate</PackageTags>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<RootNamespace>Elastic.Apm.GraphQL.HotChocolate</RootNamespace>
<AssemblyName>Elastic.Apm.GraphQL.HotChocolate</AssemblyName>
<PackageId>ElasticApm.GraphQL.HotChocolate</PackageId>
<IsPackable>true</IsPackable>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\Shared\TracerExtensions.cs" Link="Shared\TracerExtensions.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Elastic.Apm" Version="$(ElasticApmVersion)" />
<PackageReference Include="HotChocolate.Execution" Version="$(HotChocolateVersion)" />
</ItemGroup>

</Project>
47 changes: 47 additions & 0 deletions src/Elastic.Apm.Internals/CompositeDisposable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;

namespace Elastic.Apm
{
internal sealed class CompositeDisposable : IDisposable
{
private readonly List<IDisposable> _disposables = new List<IDisposable>();
private readonly object _lock = new object();

private bool _isDisposed;

public void Dispose()
{
if (_isDisposed)
{
return;
}

lock (_lock)
{
if (_isDisposed)
{
return;
}

_isDisposed = true;

foreach (var d in _disposables)
{
d.Dispose();
}
}
}

public CompositeDisposable Add(IDisposable disposable)
{
if (_isDisposed)
{
throw new ObjectDisposedException(nameof(CompositeDisposable));
}

_disposables.Add(disposable);
return this;
}
}
}
26 changes: 26 additions & 0 deletions src/Elastic.Apm.Messaging.MassTransit/Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace Elastic.Apm.Messaging.MassTransit
{
internal struct Constants
{
internal const string TraceHeaderName = "Elastic.Apm";

internal struct DiagnosticListener
{
internal const string Name = "MassTransit";
}

internal struct Events
{
internal const string SendStart = "MassTransit.Transport.Send.Start";
internal const string SendStop = "MassTransit.Transport.Send.Stop";
internal const string ReceiveStart = "MassTransit.Transport.Receive.Start";
internal const string ReceiveStop = "MassTransit.Transport.Receive.Stop";
}

internal struct Apm
{
internal const string Type = "messaging";
internal const string SendAction = "send";
}
}
}
8 changes: 8 additions & 0 deletions src/Elastic.Apm.Messaging.MassTransit/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project>
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)..\'))" />

<PropertyGroup>
<PackageTags>apm monitoring elastic elasticapm analytics messaging masstransit</PackageTags>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<RootNamespace>Elastic.Apm.Messaging.MassTransit</RootNamespace>
<AssemblyName>Elastic.Apm.Messaging.MassTransit</AssemblyName>
<PackageId>ElasticApm.Messaging.MassTransit</PackageId>
<IsPackable>true</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Elastic.Apm" Version="$(ElasticApmVersion)" />
<PackageReference Include="MassTransit" Version="$(MassTransitVersion)" />
</ItemGroup>

<ItemGroup>
<Compile Include="..\Elastic.Apm.Internals\CompositeDisposable.cs" Link="Internals\CompositeDisposable.cs" />
<Compile Include="..\Shared\TracerExtensions.cs" Link="Shared\TracerExtensions.cs" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Diagnostics;

namespace Elastic.Apm.Messaging.MassTransit
{
internal class MassTransitDiagnosticInitializer : IObserver<DiagnosticListener>, IDisposable
{
private readonly IApmAgent _apmAgent;
private IDisposable? _sourceSubscription;

internal MassTransitDiagnosticInitializer(IApmAgent apmAgent)
{
_apmAgent = apmAgent;
}

public void Dispose() => _sourceSubscription?.Dispose();

public void OnCompleted()
{
}

public void OnError(Exception error)
{
}

public void OnNext(DiagnosticListener value)
{
if (string.Equals(value.Name, Constants.DiagnosticListener.Name,
StringComparison.InvariantCultureIgnoreCase))
{
_sourceSubscription = value.Subscribe(new MassTransitDiagnosticListener(_apmAgent));
}
}
}
}
Loading

0 comments on commit 2791f65

Please sign in to comment.