コード例 #1
0
 private void OverwriteErrorAttribute(IAttributeValue errorAttr, ref bool?success)
 {
     if (errorAttr != null)
     {
         success = errorAttr.Match((s) => !(s == "true"), (b) => !b, null, null, null);
     }
 }
コード例 #2
0
        private void OverwriteSpanKindFromAttribute(IAttributeValue spanKindAttr, ref SpanKind resultKind)
        {
            // override span kind with attribute named span.kind
            if (spanKindAttr != null)
            {
                var kind = spanKindAttr.Match((s) => s, null, null, null, null);

                switch (kind.ToLower(CultureInfo.InvariantCulture))
                {
                case "server":
                    resultKind = SpanKind.Server;
                    break;

                case "client":
                    resultKind = SpanKind.Client;
                    break;

                case "producer":
                    resultKind = SpanKind.Producer;
                    break;

                case "consumer":
                    resultKind = SpanKind.Consumer;
                    break;

                default:
                    resultKind = SpanKind.Internal;
                    break;
                }
            }
        }
コード例 #3
0
        public static Google.Cloud.Trace.V2.AttributeValue ToAttributeValue(this IAttributeValue av)
        {
            var ret = av.Match(
                (s) => new Google.Cloud.Trace.V2.AttributeValue()
            {
                StringValue = new TruncatableString()
                {
                    Value = s
                }
            },
                (b) => new Google.Cloud.Trace.V2.AttributeValue()
            {
                BoolValue = b
            },
                (l) => new Google.Cloud.Trace.V2.AttributeValue()
            {
                IntValue = l
            },
                (d) => new Google.Cloud.Trace.V2.AttributeValue()
            {
                StringValue = new TruncatableString()
                {
                    Value = d.ToString()
                }
            },
                (obj) => new Google.Cloud.Trace.V2.AttributeValue()
            {
                StringValue = new TruncatableString()
                {
                    Value = obj.ToString()
                }
            });

            return(ret);
        }
コード例 #4
0
 private string AttributeValueToString(IAttributeValue attributeValue)
 {
     return(attributeValue.Match(
                (arg) => { return arg; },
                (arg) => { return arg.ToString(); },
                (arg) => { return arg.ToString(); },
                (arg) => { return null; }));
 }
コード例 #5
0
 private string AttributeToSimpleString(IAttributeValue value)
 {
     return(value.Match <string>(
                x => x.ToString(),
                x => x ? "true" : "false",
                x => x.ToString(),
                x => x.ToString(),
                x => x.ToString()
                ));
 }
コード例 #6
0
        private void OverwriteSpanKindFromAttribute(IAttributeValue spanKindAttr, ref SpanKind resultKind)
        {
            // override span kind with attribute named span.kind
            if (spanKindAttr != null)
            {
                var kind = spanKindAttr.Match((s) => s, null, null, null, null);

                if (kind == "server")
                {
                    resultKind = SpanKind.Server;
                }
                else
                {
                    resultKind = SpanKind.Client;
                }
            }
        }
コード例 #7
0
 private bool IsServerSpanKind(IAttributeValue value)
 {
     return(value.Match(
                (arg) =>
     {
         return arg.Equals(SpanAttributeConstants.ServerSpanKind);
     },
                (arg) =>
     {
         return false;
     },
                (arg) =>
     {
         return false;
     },
                (arg) =>
     {
         return false;
     }));
 }
コード例 #8
0
        private void OverwriteFieldsForHttpSpans(
            IAttributeValue httpMethodAttr,
            IAttributeValue httpUrlAttr,
            IAttributeValue httpHostAttr,
            IAttributeValue httpPathAttr,
            IAttributeValue httpStatusCodeAttr,
            IAttributeValue httpUserAgentAttr,
            IAttributeValue httpRouteAttr,
            IAttributeValue httpPortAttr,
            ref string name,
            ref string resultCode,
            ref string data,
            ref string target,
            ref string type,
            ref string userAgent)
        {
            if (httpStatusCodeAttr != null)
            {
                resultCode = httpStatusCodeAttr.Match((s) => s, null, (l) => l.ToString(CultureInfo.InvariantCulture), null, null);
                type       = "Http";
            }

            Uri url = null;

            if (httpUrlAttr != null)
            {
                var urlString = httpUrlAttr.Match((s) => s, null, null, null, null);
                Uri.TryCreate(urlString, UriKind.RelativeOrAbsolute, out url);
            }

            string httpMethod = null;
            string httpPath   = null;
            string httpHost   = null;
            string httpRoute  = null;
            string httpPort   = null;

            if (httpMethodAttr != null)
            {
                httpMethod = httpMethodAttr.Match((s) => s, null, null, null, null);
                type       = "Http";
            }

            if (httpPathAttr != null)
            {
                httpPath = httpPathAttr.Match((s) => s, null, null, null, null);
                type     = "Http";
            }

            if (httpHostAttr != null)
            {
                httpHost = httpHostAttr.Match((s) => s, null, null, null, null);
                type     = "Http";
            }

            if (httpUserAgentAttr != null)
            {
                userAgent = httpUserAgentAttr.Match((s) => s, null, null, null, null);
                type      = "Http";
            }

            if (httpRouteAttr != null)
            {
                httpRoute = httpRouteAttr.Match((s) => s, null, null, null, null);
                type      = "Http";
            }

            if (httpRouteAttr != null)
            {
                httpRoute = httpRouteAttr.Match((s) => s, null, null, null, null);
                type      = "Http";
            }

            if (httpPortAttr != null)
            {
                httpPort = httpPortAttr.Match((s) => s, null, (l) => l.ToString(), null, null);
                type     = "Http";
            }

            // restore optional fields when possible
            if ((httpPathAttr == null) && (url != null))
            {
                if (url.IsAbsoluteUri)
                {
                    httpPath = url.LocalPath;
                }
                else
                {
                    int idx = url.OriginalString.IndexOf('?');
                    if (idx != -1)
                    {
                        httpPath = url.OriginalString.Substring(0, idx);
                    }
                    else
                    {
                        httpPath = url.OriginalString;
                    }
                }
            }

            if (url == null)
            {
                string urlString = string.Empty;
                if (!string.IsNullOrEmpty(httpHost))
                {
                    urlString += "https://" + httpHost;

                    if (!string.IsNullOrEmpty(httpPort))
                    {
                        urlString += ":" + httpPort;
                    }
                }

                if (!string.IsNullOrEmpty(httpPath))
                {
                    if (httpPath[0] != '/')
                    {
                        urlString += '/';
                    }

                    urlString += httpPath;
                }

                if (!string.IsNullOrEmpty(urlString))
                {
                    Uri.TryCreate(urlString, UriKind.RelativeOrAbsolute, out url);
                }
            }

            // overwriting
            if (httpPath != null || httpMethod != null || httpRoute != null)
            {
                if (httpRoute != null)
                {
                    name = (httpMethod + " " + httpRoute).Trim();
                }
                else
                {
                    name = (httpMethod + " " + httpPath).Trim();
                }
            }

            if (url != null)
            {
                data = url.ToString();
            }

            if ((url != null) && url.IsAbsoluteUri)
            {
                target = url.Host;
            }
        }