Skip to content

Commit

Permalink
Emit spans for sdk (#156)
Browse files Browse the repository at this point in the history
* Emit spans for SDK calls

* Add context to pages and iterators

* Add tracing to pages and iterators

* Regenerate tests

* Add null checks

* Avoid name conflicts from embedded structs

* Address feedback

* Remove comment for use of IsEnabled

* don't use fmt
  • Loading branch information
Vlad Barosan authored Oct 22, 2018
1 parent a5f3812 commit 4ad539b
Show file tree
Hide file tree
Showing 86 changed files with 7,685 additions and 648 deletions.
8 changes: 6 additions & 2 deletions src/CodeNamerGo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,24 @@ public class CodeNamerGo : CodeNamer

public virtual IEnumerable<string> AutorestImports => new string[] { PrimaryTypeGo.GetImportLine(package: "github.com/Azure/go-autorest/autorest") };

public virtual IEnumerable<string> TracingImports => new string[] { PrimaryTypeGo.GetImportLine(package: "github.com/Azure/go-autorest/tracing") };

public virtual IEnumerable<string> StandardImports => new string[]
{
PrimaryTypeGo.GetImportLine(package: "github.com/Azure/go-autorest/autorest/azure"),
PrimaryTypeGo.GetImportLine(package: "net/http"),
PrimaryTypeGo.GetImportLine(package: "context")
PrimaryTypeGo.GetImportLine(package: "context"),
};

public virtual IEnumerable<string> PageableImports => new string[]
{
PrimaryTypeGo.GetImportLine(package: "net/http"),
PrimaryTypeGo.GetImportLine(package: "context"),
PrimaryTypeGo.GetImportLine(package: "github.com/Azure/go-autorest/tracing"),
PrimaryTypeGo.GetImportLine(package: "github.com/Azure/go-autorest/autorest/to")
};

public virtual IEnumerable<string> ValidationImport => new string[] { PrimaryTypeGo.GetImportLine(package: "github.com/Azure/go-autorest/autorest/validation") };
public virtual IEnumerable<string> ValidationImports => new string[] { PrimaryTypeGo.GetImportLine(package: "github.com/Azure/go-autorest/autorest/validation") };

public string[] UserDefinedNames => new string[] {
"UserAgent",
Expand Down
26 changes: 25 additions & 1 deletion src/Model/CodeModelGo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using AutoRest.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
Expand All @@ -17,6 +18,7 @@ public class CodeModelGo : CodeModel
{
public static readonly string OneVerString = "version.Number";
private static readonly Regex semVerPattern = new Regex(@"^v?(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)(?:-(?<tag>\S+))?$", RegexOptions.Compiled);
private const string sdkFqdnPrefix = "github.com/Azure/azure-sdk-for-go";

public CodeModelGo()
{
Expand Down Expand Up @@ -106,6 +108,28 @@ private string SpecifiedUserAgent

public string APIType => Settings.Instance.Host?.GetValue<string>("openapi-type").Result;

public string PackageFqdn
{
get
{
var outDir = Settings.Instance.Host?.GetValue<string>("output-folder").Result.ToLowerInvariant().Replace("\\", "/");
var sdkPath = Settings.Instance.Host?.GetValue<string>("go-sdk-folder").Result?.ToLowerInvariant().Replace("\\", "/").Trim();

if (!string.IsNullOrEmpty(sdkPath))
{
return $"{sdkFqdnPrefix}/{outDir.Split(sdkPath, StringSplitOptions.None).Last()}";
}
else if (!Path.IsPathRooted(outDir))
{
return outDir;
}
else
{
return outDir.Substring(Path.GetPathRoot(outDir).Length);
}
}
}

public IEnumerable<string> ClientImports
{
get
Expand Down Expand Up @@ -303,7 +327,7 @@ public override string Namespace

/// FormatVersion normalizes a version string into a SemVer if it resembles one. Otherwise,
/// it returns the original string unmodified. If version is empty or only comprised of
/// whitespace,
/// whitespace,
public static string FormatVersion(string version)
{

Expand Down
6 changes: 6 additions & 0 deletions src/Model/IteratorTypeGo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ internal class IteratorTypeGo : CompositeTypeGo
public IteratorTypeGo(PageTypeGo pageType) : base(CodeNamerGo.Instance.GetIteratorTypeName(pageType))
{
PageType = pageType;
CodeModel = pageType.CodeModel;
Documentation = $"Provides access to a complete listing of {PageType.ElementType.Name} values.";
}

Expand All @@ -35,6 +36,11 @@ public IteratorTypeGo(PageTypeGo pageType) : base(CodeNamerGo.Instance.GetIterat
/// </summary>
public string IndexField => "i";

/// <summary>
/// The qualified name for the advancer method.
/// </summary>
public string AdvancerQualifiedName => $"{Name}.NextWithContext";

/// <summary>
/// Gets the name of the page field that contains the current page of values.
/// </summary>
Expand Down
6 changes: 5 additions & 1 deletion src/Model/MethodGo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public class MethodGo : Method

public bool NextAlreadyDefined { get; private set; }

/// <summary>
/// The method name qualified with the client name
/// </summary>
public string QualifiedName => $"{Owner}.{Name}";

public bool IsCustomBaseUri
=> CodeModel.Extensions.ContainsKey(SwaggerExtensions.ParameterizedHostExtension);

Expand All @@ -47,7 +52,6 @@ internal void Transform(CodeModelGo cmg)
Owner = (MethodGroup as MethodGroupGo).ClientName;
PackageName = cmg.Namespace;
NextAlreadyDefined = NextMethodExists(cmg.Methods.Cast<MethodGo>());

var apiVersionParam =
from p in Parameters
let name = p.SerializedName
Expand Down
4 changes: 3 additions & 1 deletion src/Model/MethodGroupGo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,16 @@ internal void Transform(CodeModelGo cmg)
var imports = new HashSet<string>();
imports.UnionWith(CodeNamerGo.Instance.AutorestImports);
imports.UnionWith(CodeNamerGo.Instance.StandardImports);
imports.UnionWith(CodeNamerGo.Instance.TracingImports);


cmg.Methods.Where(m => m.Group.Value == Name)
.ForEach(m =>
{
var mg = m as MethodGo;
if ((CodeModel as CodeModelGo).ShouldValidate && !mg.ParameterValidations.IsNullOrEmpty())
{
imports.UnionWith(CodeNamerGo.Instance.ValidationImport);
imports.UnionWith(CodeNamerGo.Instance.ValidationImports);
}
mg.ParametersGo.ForEach(p => p.AddImports(imports));
if (mg.HasReturnValue() && !mg.ReturnValue().Body.PrimaryType(KnownPrimaryType.Stream))
Expand Down
7 changes: 6 additions & 1 deletion src/Model/PageTypeGo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,14 @@ public PageTypeGo(MethodGo method) : base(CodeNamerGo.Instance.GetPageTypeName(m
/// </summary>
public string ResultFieldName => ContentType.Name.ToVariableName();

/// <summary>
/// The qualified name for the advancer method.
/// </summary>
public string AdvancerQualifiedName => $"{Name}.NextWithContext";

public override string Fields()
{
return $" {FnFieldName} func({ContentType.Name}) ({ContentType.Name}, error)\n {ResultFieldName} {ContentType.Name}";
return $" {FnFieldName} func(context.Context, {ContentType.Name}) ({ContentType.Name}, error)\n {ResultFieldName} {ContentType.Name}";
}

public override bool Equals(object other)
Expand Down
Loading

0 comments on commit 4ad539b

Please sign in to comment.