diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1ff0c42 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4ce6fdd --- /dev/null +++ b/.gitignore @@ -0,0 +1,340 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- Backup*.rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..f4f95a2 --- /dev/null +++ b/README.md @@ -0,0 +1,25 @@ +# sentry dotnet transaction addon +### Unnoficial addon for adding Peformance support to Sentry-dotnet + +Official Docs: https://docs.sentry.io/performance-monitoring/getting-started/ + +##### Usage: + +```C# +SentryTracingSDK.Init(dsn, tracesSampleRate); can be called before or after SentrySdk.Init. + +var transaction = SentryTracingSDK.StartTransaction( name );// return a new transaction. +var child = transaction.StartChild( name );// return a new child +child.Finish();// finishes the child +// You can add as many childs as you wish on a transaction +transaction.Finish();// finishes and sends the transaction +``` + +##### You'll need to add an additional code inside of your BeforeSend code +```C# +if (arg is SentryTransaction transaction) +{ + transaction.SendTransaction(); + return null; +} +``` diff --git a/sentry-dotnet-transaction-addon.sln b/sentry-dotnet-transaction-addon.sln new file mode 100644 index 0000000..daf2577 --- /dev/null +++ b/sentry-dotnet-transaction-addon.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30204.135 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "sentry-dotnet-transaction-addon", "sentry-dotnet-transaction-addon\sentry-dotnet-transaction-addon.csproj", "{BDA414FB-FACE-4867-BB3D-8B3DE73B79D2}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {BDA414FB-FACE-4867-BB3D-8B3DE73B79D2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BDA414FB-FACE-4867-BB3D-8B3DE73B79D2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BDA414FB-FACE-4867-BB3D-8B3DE73B79D2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BDA414FB-FACE-4867-BB3D-8B3DE73B79D2}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {0458D24F-B240-45A0-9CC4-B8A1A84F1AA0} + EndGlobalSection +EndGlobal diff --git a/sentry-dotnet-transaction-addon/Converters/JsonDateEpochConverter.cs b/sentry-dotnet-transaction-addon/Converters/JsonDateEpochConverter.cs new file mode 100644 index 0000000..152d661 --- /dev/null +++ b/sentry-dotnet-transaction-addon/Converters/JsonDateEpochConverter.cs @@ -0,0 +1,31 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace sentry_dotnet_transaction_addon.Converters +{ + public class JsonDateEpochConverter : DateTimeConverterBase + { + private static readonly DateTime _epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); + + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + if (value is DateTimeOffset date) + { + writer.WriteRawValue((date - _epoch).TotalSeconds.ToString()); + } + else + { + writer.WriteRawValue(((DateTime)value - _epoch).TotalSeconds.ToString()); + } + } + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + if (reader.Value == null) { return null; } + return _epoch.AddMilliseconds((long)reader.Value / 1000d); + } + } +} diff --git a/sentry-dotnet-transaction-addon/Extensions/DsnExtensions.cs b/sentry-dotnet-transaction-addon/Extensions/DsnExtensions.cs new file mode 100644 index 0000000..b7d84d9 --- /dev/null +++ b/sentry-dotnet-transaction-addon/Extensions/DsnExtensions.cs @@ -0,0 +1,12 @@ +using Sentry; + +namespace sentry_dotnet_transaction_addon.Extensions +{ + internal static class DsnExtensions + { + internal static string GetTracingUrl(this Dsn dsn) + { + return $"{dsn.SentryUri.Scheme}://{dsn.SentryUri.Host}/api/{dsn.ProjectId}/envelope/?sentry_key={dsn.PublicKey}&sentry_version=7"; + } + } +} diff --git a/sentry-dotnet-transaction-addon/Extensions/GuidExtensions.cs b/sentry-dotnet-transaction-addon/Extensions/GuidExtensions.cs new file mode 100644 index 0000000..1c0bc92 --- /dev/null +++ b/sentry-dotnet-transaction-addon/Extensions/GuidExtensions.cs @@ -0,0 +1,13 @@ +using System; + +namespace sentry_dotnet_transaction_addon.Extensions +{ + internal static class GuidExtensions + { + internal static string LimitLength(this Guid guid, int length = 16) + { + var output = guid.ToString().Replace("-", ""); + return output.Length > length ? output.Remove(length) : output; + } + } +} diff --git a/sentry-dotnet-transaction-addon/ITransactionEvent.cs b/sentry-dotnet-transaction-addon/ITransactionEvent.cs new file mode 100644 index 0000000..94101bd --- /dev/null +++ b/sentry-dotnet-transaction-addon/ITransactionEvent.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; + +namespace sentry_dotnet_transaction_addon +{ + public interface ITransactionEvent + { + List Spans { get; } + + DateTimeOffset StartTimestamp { get; } + } +} diff --git a/sentry-dotnet-transaction-addon/Internals/EventIdSentData.cs b/sentry-dotnet-transaction-addon/Internals/EventIdSentData.cs new file mode 100644 index 0000000..446ff8e --- /dev/null +++ b/sentry-dotnet-transaction-addon/Internals/EventIdSentData.cs @@ -0,0 +1,12 @@ +using Newtonsoft.Json; + +namespace sentry_dotnet_transaction_addon.Internals +{ + internal class EventIdSentData + { + [JsonProperty("event_id")] + public string EventId { get; set; } + [JsonProperty("sent_at")] + public string SentAt { get; set; } + } +} diff --git a/sentry-dotnet-transaction-addon/SentryTracing.cs b/sentry-dotnet-transaction-addon/SentryTracing.cs new file mode 100644 index 0000000..962f636 --- /dev/null +++ b/sentry-dotnet-transaction-addon/SentryTracing.cs @@ -0,0 +1,66 @@ +using Sentry; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace sentry_dotnet_transaction_addon +{ + public class SentryTracing : ITransactionEvent, IDisposable + { + public List Spans { get; private set; } + public DateTimeOffset StartTimestamp { get; private set; } + + internal Trace Trace { get; private set; } + public string Transaction { get; private set; } + public SentryTracing(string name) + { + Trace = new Trace(); + Transaction = name; + StartTimestamp = DateTimeOffset.Now; + Spans = new List(); + } + + public string Id => Guid.NewGuid().ToString(); + + public Span GetSpan(string op) + { + return Spans.FirstOrDefault(s => s.Op == op); + } + + public Span StartChild(string description, string op = null) + { + var span = new Span(description, op); + SetTraceToSpan(span); + Spans.Add(span); + return span; + } + + private void SetTraceToSpan(Span span) + { + span.TraceId = Trace.TraceId; + span.ParentSpanId = Trace.SpanId; + } + + public void Finish() + { + if (SentryTracingSDK.IsEnabled() && new Random().NextDouble() <= SentryTracingSDK.TracingOptions.TracesSampleRate) + { + var @event = new SentryTracingEvent(this); + if (SentryTracingSDK.TracingOptions.RegisterTracingBreadcrmub) + { + SentrySdk.AddBreadcrumb(@event.EventId.ToString(), "sentry.transaction"); + } + SentrySdk.WithScope(scope => + { + SentrySdk.CaptureEvent(@event); + }); + } + SentryTracingSDK.DisposeTracingEvent(this); + } + + public void Dispose() + { + Finish(); + } + } +} diff --git a/sentry-dotnet-transaction-addon/SentryTracingEvent.cs b/sentry-dotnet-transaction-addon/SentryTracingEvent.cs new file mode 100644 index 0000000..88a9e0a --- /dev/null +++ b/sentry-dotnet-transaction-addon/SentryTracingEvent.cs @@ -0,0 +1,65 @@ +using Newtonsoft.Json; +using Sentry; +using sentry_dotnet_transaction_addon.Converters; +using sentry_dotnet_transaction_addon.Extensions; +using sentry_dotnet_transaction_addon.Internals; +using System; +using System.Collections.Generic; +using System.Net.Http; +using System.Threading.Tasks; + +namespace sentry_dotnet_transaction_addon +{ + public class SentryTracingEvent : SentryEvent, ITransactionEvent + { + [JsonProperty("type")] + public string Type { get; private set; } + + [JsonProperty("spans")] + public List Spans { get; private set; } + + [JsonProperty("start_timestamp")] + public DateTimeOffset StartTimestamp { get; private set; } + + internal SentryTracingEvent(SentryTracing transactionEvent) + { + Transaction = transactionEvent.Transaction; + Type = "transaction"; + try + { + Contexts.AddOrUpdate("trace", transactionEvent.Trace, (id, trace) => trace); + } + catch (Exception e) + { + + } + Spans = transactionEvent.Spans; + StartTimestamp = transactionEvent.StartTimestamp; + } + + public void SendTransaction() + { + Level = null; + var json = JsonConvert.SerializeObject(this, new JsonDateEpochConverter()); + new Task(async () => + { + try + { + using (var client = new HttpClient()) + { + var @event = JsonConvert.SerializeObject(new EventIdSentData() + { + EventId = EventId.ToString(), + SentAt = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:MM:ss.ffZ") + }); + var @type = "{\"type\"=\"transaction\"}"; + var content = new StringContent(@event + '\n' + @type + '\n' + json); + var url = SentryTracingSDK.TracingOptions.Dsn.GetTracingUrl(); + var @return = await client.PostAsync(url, content); + } + } + finally { } + }).Start(); + } + } +} \ No newline at end of file diff --git a/sentry-dotnet-transaction-addon/SentryTracingEventProcessor.cs b/sentry-dotnet-transaction-addon/SentryTracingEventProcessor.cs new file mode 100644 index 0000000..2e936bc --- /dev/null +++ b/sentry-dotnet-transaction-addon/SentryTracingEventProcessor.cs @@ -0,0 +1,18 @@ +using Sentry; +using Sentry.Extensibility; + +namespace sentry_dotnet_transaction_addon +{ + public class SentryTracingEventProcessor : ISentryEventProcessor + { + public SentryEvent Process(SentryEvent @event) + { + if (@event is SentryTracingEvent performanceEvent) + { + performanceEvent.SendTransaction(); + return null; + } + return @event; + } + } +} diff --git a/sentry-dotnet-transaction-addon/SentryTracingOptions.cs b/sentry-dotnet-transaction-addon/SentryTracingOptions.cs new file mode 100644 index 0000000..fc14764 --- /dev/null +++ b/sentry-dotnet-transaction-addon/SentryTracingOptions.cs @@ -0,0 +1,29 @@ +using Sentry; + +namespace sentry_dotnet_transaction_addon +{ + public class SentryTracingOptions + { + public SentryTracingOptions(Dsn dsn, double tracesSampleRate = 1.0, bool registerTracingBreadcrumb = true) + { + Dsn = dsn; + TracesSampleRate = tracesSampleRate; + RegisterTracingBreadcrmub = registerTracingBreadcrumb; + } + + public Dsn Dsn { get; set; } + /// + /// the rate of sending events where + /// 1.0 you always send a performance Event. + /// 0 You'll never send events. + /// + public double TracesSampleRate { get; set; } + + /// + /// When set to true, it'll always register a breadcrumb with + ///
the given tracing event Id if the event is sent to Sentry
+ ///
+ public bool RegisterTracingBreadcrmub { get; set; } + + } +} diff --git a/sentry-dotnet-transaction-addon/SentryTracingSDK.cs b/sentry-dotnet-transaction-addon/SentryTracingSDK.cs new file mode 100644 index 0000000..03065f9 --- /dev/null +++ b/sentry-dotnet-transaction-addon/SentryTracingSDK.cs @@ -0,0 +1,68 @@ +using Sentry; +using System.Collections.Generic; +using System.Linq; + +namespace sentry_dotnet_transaction_addon +{ + public static class SentryTracingSDK + { + internal static List> _transactionStorage = new List>(); + + internal static SentryTracingOptions TracingOptions { get; set; } + + /// + /// Initialize the Tracing Sdk. + /// + public static void Init(string dsn) + { + Init(new SentryTracingOptions(new Dsn(dsn))); + } + + /// + /// Initialize the Tracing Sdk. + /// + public static void Init(Dsn dsn) + { + Init(new SentryTracingOptions(dsn)); + } + + /// + /// Initialize the Tracing Sdk. + /// + public static void Init(SentryTracingOptions options) + { + TracingOptions = options; + } + + public static bool IsEnabled() => TracingOptions != null; + + public static void Close() + { + _transactionStorage.Clear(); + _transactionStorage = null; + TracingOptions = null; + } + + public static SentryTracing StartTransaction(string name) + { + var tracing = new SentryTracing(name); + _transactionStorage.Add(new KeyValuePair(name, tracing)); + return tracing; + } + + public static SentryTracing RetreiveTransactionById(string id) + { + return _transactionStorage.FirstOrDefault(p => p.Value.Id == id).Value;//<- it could go kaboom + } + + public static SentryTracing RetreiveTransactionByName(string name) + { + return _transactionStorage.FirstOrDefault(p => p.Key == name).Value;//<- it could go kaboom + } + + internal static void DisposeTracingEvent(SentryTracing tracing) + { + _transactionStorage.Remove(_transactionStorage.First(p => p.Key == tracing.Transaction && p.Value.Equals(tracing))); + } + } +} diff --git a/sentry-dotnet-transaction-addon/Span.cs b/sentry-dotnet-transaction-addon/Span.cs new file mode 100644 index 0000000..5ce2f45 --- /dev/null +++ b/sentry-dotnet-transaction-addon/Span.cs @@ -0,0 +1,44 @@ +using Newtonsoft.Json; +using System; +using sentry_dotnet_transaction_addon.Extensions; + +namespace sentry_dotnet_transaction_addon +{ + public class Span + { + #region Properties + [JsonProperty("description")] + public string Description; + + [JsonProperty("op")] + public string Op; + + [JsonProperty("span_id")] + public string SpanId; + + [JsonProperty("parent_span_id")] + public string ParentSpanId; + + [JsonProperty("start_timestamp")] + public DateTimeOffset StartTimestamp; + + [JsonProperty("timestamp")] + public DateTimeOffset Timestamp; + + [JsonProperty("trace_id")] + public string TraceId; + #endregion + public Span(string description, string op = null) + { + StartTimestamp = DateTimeOffset.Now; + Description = description; + Op = op ?? description; + SpanId = Guid.NewGuid().LimitLength(); + } + + public void Finish() + { + Timestamp = DateTimeOffset.Now; + } + } +} diff --git a/sentry-dotnet-transaction-addon/Trace.cs b/sentry-dotnet-transaction-addon/Trace.cs new file mode 100644 index 0000000..aa92207 --- /dev/null +++ b/sentry-dotnet-transaction-addon/Trace.cs @@ -0,0 +1,31 @@ +using Newtonsoft.Json; +using sentry_dotnet_transaction_addon.Extensions; +using System; +using System.Diagnostics; + +namespace sentry_dotnet_transaction_addon +{ + internal class Trace + { + #region Properties + [JsonProperty("op")] + public string Op { get; private set; } + + [JsonProperty("span_id")] + public string SpanId { get; private set; } + + [JsonProperty("trace_id")] + public string TraceId { get; private set; } + #endregion + public Trace() + { + var st = new StackTrace(); + var sf = st.GetFrame(5); + + Op = sf.GetMethod().Name; + TraceId = Guid.NewGuid().LimitLength(100); + SpanId = Guid.NewGuid().LimitLength(); + + } + } +} diff --git a/sentry-dotnet-transaction-addon/sentry-dotnet-transaction-addon.csproj b/sentry-dotnet-transaction-addon/sentry-dotnet-transaction-addon.csproj new file mode 100644 index 0000000..b7e8982 --- /dev/null +++ b/sentry-dotnet-transaction-addon/sentry-dotnet-transaction-addon.csproj @@ -0,0 +1,14 @@ + + + + netstandard2.0 + sentry_dotnet_transaction_addon + + + + + + + + +