Skip to content

Commit

Permalink
Update generate code target to use new common scripts (#3033)
Browse files Browse the repository at this point in the history
* update generate code target

* update target to only generate if src dir

* update shared source
  • Loading branch information
m-nash authored Jan 31, 2023
1 parent 80418ef commit 52a33de
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/AutoRest.CSharp/build/CodeGeneration.targets
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

<PropertyGroup>
<PowerShellExe Condition="'$(PowerShellExe)' == ''">pwsh</PowerShellExe>
<CadlProjectSyncScriptPath Condition="'$(CadlProjectSyncScriptPath)' == ''">$(MSBuildProjectDirectory)/../../../../eng/scripts/Cadl-Project-Sync.ps1</CadlProjectSyncScriptPath>
<CadlProjectGenerateScriptPath Condition="'$(CadlProjectGenerateScriptPath)' == ''">$(MSBuildProjectDirectory)/../../../../eng/scripts/Cadl-Project-Generate.ps1</CadlProjectGenerateScriptPath>
<CadlProjectSyncScriptPath Condition="'$(CadlProjectSyncScriptPath)' == ''">$(MSBuildProjectDirectory)/../../../../eng/common/scripts/Cadl-Project-Sync.ps1</CadlProjectSyncScriptPath>
<CadlProjectGenerateScriptPath Condition="'$(CadlProjectGenerateScriptPath)' == ''">$(MSBuildProjectDirectory)/../../../../eng/common/scripts/Cadl-Project-Generate.ps1</CadlProjectGenerateScriptPath>
<_DefaultInputName Condition="Exists('$(MSBuildProjectDirectory)/autorest.md')">$(MSBuildProjectDirectory)/autorest.md</_DefaultInputName>
<CadlInput Condition="Exists('$(MSBuildProjectDirectory)/cadl-location.yaml')">$(MSBuildProjectDirectory)/cadl-location.yaml</CadlInput>
<CadlInput Condition="Exists('$(MSBuildProjectDirectory)/../cadl-location.yaml') and $(MSBuildProjectDirectory.EndsWith('src'))">$(MSBuildProjectDirectory)/../cadl-location.yaml</CadlInput>
<AutoRestInput Condition="'$(AutoRestInput)' == ''">$(_DefaultInputName)</AutoRestInput>
<AutoRestTestsInput Condition="Exists('$(MSBuildProjectDirectory)/autorest.tests.md')">$(MSBuildProjectDirectory)/autorest.tests.md</AutoRestTestsInput>
<AutoRestEntryPoint Condition="'$(AutoRestEntryPoint)' == ''">$(MSBuildThisFileDirectory)../tools/autorest/entrypoints/app.js</AutoRestEntryPoint>
Expand Down
27 changes: 16 additions & 11 deletions src/assets/Azure.Core.Shared/DiagnosticScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@ public void AddLink(string traceparent, string tracestate, IDictionary<string, s
(int)_kind,
startTime: _startTime,
tags: _tagCollection,
links: GetActivitySourceLinkCollection());
links: GetActivitySourceLinkCollection(),
parentId: _traceparent);
}

public void SetStartTime(DateTime startTime)
Expand All @@ -356,8 +357,11 @@ public void MarkFailed(Exception exception)

public void SetTraceparent(string traceparent)
{
if (_currentActivity != null)
{
throw new InvalidOperationException("Traceparent can not be set after the activity is started.");
}
_traceparent = traceparent;
_currentActivity?.SetParentId(traceparent);
}

public void Dispose()
Expand Down Expand Up @@ -404,7 +408,7 @@ static ActivityExtensions()
private static Action<Activity, string?>? SetTraceStateStringMethod;
private static Func<Activity, int>? GetIdFormatMethod;
private static Action<Activity, string, object?>? ActivityAddTagMethod;
private static Func<object, string, int, ICollection<KeyValuePair<string, object>>?, IList?, DateTimeOffset, Activity?>? ActivitySourceStartActivityMethod;
private static Func<object, string, int, string?, ICollection<KeyValuePair<string, object>>?, IList?, DateTimeOffset, Activity?>? ActivitySourceStartActivityMethod;
private static Func<object, bool>? ActivitySourceHasListenersMethod;
private static Func<string, string?, ICollection<KeyValuePair<string, object>>?, object?>? CreateActivityLinkMethod;
private static Func<ICollection<KeyValuePair<string,object>>?>? CreateTagsCollectionMethod;
Expand Down Expand Up @@ -667,7 +671,7 @@ public static bool ActivitySourceHasListeners(object? activitySource)
return ActivitySourceHasListenersMethod.Invoke(activitySource);
}

public static Activity? ActivitySourceStartActivity(object? activitySource, string activityName, int kind, DateTimeOffset startTime, ICollection<KeyValuePair<string, object>>? tags, IList? links)
public static Activity? ActivitySourceStartActivity(object? activitySource, string activityName, int kind, DateTimeOffset startTime, ICollection<KeyValuePair<string, object>>? tags, IList? links, string? parentId)
{
if (activitySource == null)
{
Expand All @@ -681,49 +685,50 @@ public static bool ActivitySourceHasListeners(object? activitySource)
ActivityContextType == null ||
ActivityKindType == null)
{
ActivitySourceStartActivityMethod = (_, _, _, _, _, _) => null;
ActivitySourceStartActivityMethod = (_, _, _, _, _, _, _) => null;
}
else
{
var method = ActivitySourceType?.GetMethod("StartActivity", BindingFlags.Instance | BindingFlags.Public, null, new[]
{
typeof(string),
ActivityKindType,
ActivityContextType,
typeof(string),
typeof(IEnumerable<KeyValuePair<string, object>>),
typeof(IEnumerable<>).MakeGenericType(ActivityLinkType),
typeof(DateTimeOffset)
}, null);

if (method == null)
{
ActivitySourceStartActivityMethod = (_, _, _, _, _, _) => null;
ActivitySourceStartActivityMethod = (_, _, _, _, _, _, _) => null;
}
else
{
var sourceParameter = Expression.Parameter(typeof(object));
var nameParameter = Expression.Parameter(typeof(string));
var kindParameter = Expression.Parameter(typeof(int));
var parentIdParameter = Expression.Parameter(typeof(string));
var startTimeParameter = Expression.Parameter(typeof(DateTimeOffset));
var tagsParameter = Expression.Parameter(typeof(ICollection<KeyValuePair<string, object>>));
var linksParameter = Expression.Parameter(typeof(IList));
var methodParameter = method.GetParameters();
ActivitySourceStartActivityMethod = Expression.Lambda<Func<object, string, int, ICollection<KeyValuePair<string, object>>?, IList?, DateTimeOffset, Activity?>>(
ActivitySourceStartActivityMethod = Expression.Lambda<Func<object, string, int, string?, ICollection<KeyValuePair<string, object>>?, IList?, DateTimeOffset, Activity?>>(
Expression.Call(
Expression.Convert(sourceParameter, method.DeclaringType!),
method,
nameParameter,
Expression.Convert(kindParameter, methodParameter[1].ParameterType),
Expression.Default(ActivityContextType),
Expression.Convert(parentIdParameter, methodParameter[2].ParameterType),
Expression.Convert(tagsParameter, methodParameter[3].ParameterType),
Expression.Convert(linksParameter, methodParameter[4].ParameterType),
Expression.Convert(startTimeParameter, methodParameter[5].ParameterType)),
sourceParameter, nameParameter, kindParameter, tagsParameter, linksParameter, startTimeParameter).Compile();
sourceParameter, nameParameter, kindParameter, parentIdParameter, tagsParameter, linksParameter, startTimeParameter).Compile();
}
}
}

return ActivitySourceStartActivityMethod.Invoke(activitySource, activityName, kind, tags, links, startTime);
return ActivitySourceStartActivityMethod.Invoke(activitySource, activityName, kind, parentId, tags, links, startTime);
}

public static object? CreateActivitySource(string name)
Expand Down

0 comments on commit 52a33de

Please sign in to comment.