Skip to content

Commit

Permalink
Refactor tracing context (#139)
Browse files Browse the repository at this point in the history
* Delete `ISkyWalkingClient` interface

* Use segment protocol V2

* Forget the old api. All context apis will be overwritten.

* Add segments define

* Add some apis

* Add carrierParser

* Add SegmentContextAccessor API

* Add SampledDelegate interface

* Add thread-safe  SamplerChainBuilder

* Add SegmentContextFactory

* Add ITracingContext Interface

* Refactoring the core API for tracing context

* remove utils package

* Resolve issue #57 : Provide percentage-based sampling

* Refactor HttpClient Tracing

* Fix header carrier

* Add async exitSpan sample

* Add Task.WhenAll sample

* Refactor EntityFrameworkCore tracing

* Refactor SqlClient & CAP Tracing

* Refactor Asp.Net tracing

* Remove outdated APIs
  • Loading branch information
liuhaoyang authored Feb 13, 2019
1 parent 91ab544 commit 2f24067
Show file tree
Hide file tree
Showing 152 changed files with 2,748 additions and 4,038 deletions.
14 changes: 4 additions & 10 deletions sample/SkyWalking.Sample.AspNet/skywalking.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
{
"SkyWalking": {
"ApplicationCode": "SkyWalking.Sample.AspNet",
"SpanLimitPerSegment": 300,
"Sampling": {
"SamplePer3Secs": -1
},
"ServiceName": "aspnet-sample",
"Logging": {
"Level": "Information",
"FilePath": "logs\\SkyWalking-{Date}.log"
"Level": "Debug",
"FilePath": "/tmp/logs/SkyWalking-{Date}.log"
},
"Transport": {
"Interval": 3000,
"PendingSegmentLimit": 30000,
"PendingSegmentTimeout": 1000,
"gRPC": {
"Servers": "localhost:11800",
"Timeout": 2000,
"Timeout": 10000,
"ConnectTimeout": 10000
}
}
Expand Down
17 changes: 17 additions & 0 deletions sample/SkyWalking.Sample.Backend/Controllers/DelayController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace SkyWalking.Sample.Backend.Controllers
{
[Route("api/[controller]")]
public class DelayController : Controller
{
// GET
[HttpGet("{delay}")]
public async Task<string> Get(int delay)
{
await Task.Delay(delay);
return $"delay {delay}ms";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using SkyWalking.Tracing;

namespace SkyWalking.Sample.Backend.Sampling
{
public class CustomSamplingInterceptor : ISamplingInterceptor
{
public int Priority { get; } = 0;

public bool Invoke(SamplingContext samplingContext, Sampler next)
{
return next(samplingContext);
}
}
}
4 changes: 4 additions & 0 deletions sample/SkyWalking.Sample.Backend/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using SkyWalking.Sample.Backend.Models;
using SkyWalking.Sample.Backend.Sampling;
using SkyWalking.Tracing;

namespace SkyWalking.Sample.Backend
{
Expand All @@ -26,6 +28,8 @@ public void ConfigureServices(IServiceCollection services)
sqliteConnection.Open();

services.AddEntityFrameworkSqlite().AddDbContext<SampleDbContext>(c => c.UseSqlite(sqliteConnection));

services.AddSingleton<ISamplingInterceptor, CustomSamplingInterceptor>();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
Expand Down
16 changes: 13 additions & 3 deletions sample/SkyWalking.Sample.Frontend/Controllers/ValuesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,21 @@ namespace SkyWalking.Sample.Frontend.Controllers
public class ValuesController : Controller
{
// GET api/values
[HttpGet("/values")]
[HttpGet]
public async Task<IEnumerable<string>> Get()
{
await new HttpClient().GetAsync("http://localhost:5002/api/values");
return new string[] { "value1", "value2" };
}
return new string[] {"value1", "value2"};
}

[HttpGet("{id}")]
public async Task<string> Get(int id)
{
var client = new HttpClient();
Task.WhenAll(client.GetAsync("http://localhost:5002/api/delay/2000"),
client.GetAsync("http://localhost:5002/api/values"),
client.GetAsync("http://localhost:5002/api/delay/200"));
return await client.GetStringAsync("http://localhost:5002/api/delay/100");
}
}
}
2 changes: 1 addition & 1 deletion sample/SkyWalking.Sample.Frontend/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}
},
"SkyWalking": {
"ApplicationCode": "asp-net-core-frontend"
"ServiceName": "asp-net-core-frontend"
}
}

41 changes: 41 additions & 0 deletions src/SkyWalking.Abstractions/Common/Components.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Licensed to the OpenSkywalking under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenSkywalking licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

namespace SkyWalking.Common
{
public static class Components
{
public static readonly StringOrIntValue ASPNETCORE= new StringOrIntValue("AspNetCore");

public static readonly StringOrIntValue HTTPCLIENT = new StringOrIntValue("HttpClient");

public static readonly StringOrIntValue ENTITYFRAMEWORKCORE = new StringOrIntValue("EntityFrameworkCore");

public static readonly StringOrIntValue SQLCLIENT = new StringOrIntValue("SqlClient");

public static readonly StringOrIntValue CAP = new StringOrIntValue("CAP");

public static readonly StringOrIntValue ENTITYFRAMEWORKCORE_SQLITE = new StringOrIntValue("EntityFrameworkCore.Sqlite");

public static readonly StringOrIntValue POMELO_ENTITYFRAMEWORKCORE_MYSQL = new StringOrIntValue("Pomelo.EntityFrameworkCore.MySql");

public static readonly StringOrIntValue NPGSQL_ENTITYFRAMEWORKCORE_POSTGRESQL = new StringOrIntValue("Npgsql.EntityFrameworkCore.PostgreSQL");

public static readonly StringOrIntValue ASPNET = new StringOrIntValue("AspNet");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
*/

namespace SkyWalking
namespace SkyWalking.Common
{
public struct NullableValue
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
*/

namespace SkyWalking
namespace SkyWalking.Common
{
public struct StringOrIntValue
{
Expand All @@ -29,6 +29,8 @@ public StringOrIntValue(int value)
_stringValue = null;
}

public bool HasValue => HasIntValue || HasStringValue;

public bool HasIntValue => _intValue != 0;

public bool HasStringValue => _stringValue != null;
Expand All @@ -53,5 +55,11 @@ public StringOrIntValue(int intValue, string stringValue)
{
return (_stringValue, _intValue);
}

public override string ToString()
{
if (HasIntValue) return _intValue.ToString();
return _stringValue;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Licensed to the OpenSkywalking under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
Expand All @@ -16,30 +16,27 @@
*
*/

using SkyWalking.Context.Ids;

namespace SkyWalking.Context
namespace SkyWalking.Common
{
public interface IContextSnapshot
public static class Tags
{
string EntryOperationName { get; set; }

string ParentOperationName { get; set; }

DistributedTraceId DistributedTraceId { get; }

int EntryApplicationInstanceId { get; set; }
public static readonly string URL = "url";

public static readonly string PATH = "path";

int SpanId { get; }

bool IsFromCurrent { get; }
public static readonly string HTTP_METHOD = "http.method";

bool IsValid { get; }
public static readonly string STATUS_CODE = "status_code";

ID TraceSegmentId { get; }
public static readonly string DB_TYPE = "db.type";

int EntryOperationId { set; }
public static readonly string DB_INSTANCE = "db.instance";

public static readonly string DB_STATEMENT = "db.statement";

int ParentOperationId { set; }
public static readonly string DB_BIND_VARIABLES = "db.bind_vars";

public static readonly string MQ_TOPIC = "mq.topic";
}
}
59 changes: 0 additions & 59 deletions src/SkyWalking.Abstractions/Components/ComponentsDefine.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,22 @@
namespace SkyWalking.Config
{
[Config("SkyWalking")]
public class InstrumentationConfig
public class InstrumentConfig
{
public string Namespace { get; set; }

[Obsolete("Use ServiceName.")]
public string ApplicationCode { get; set; }

public string ServiceName { get; set; }

public string[] HeaderVersions { get; set; }
}

public int SpanLimitPerSegment { get; set; } = 300;
public static class HeaderVersions
{
public static string SW3 { get; } = "sw3";

public static string SW6 { get; } = "sw6";
}
}
2 changes: 2 additions & 0 deletions src/SkyWalking.Abstractions/Config/SamplingConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ namespace SkyWalking.Config
public class SamplingConfig
{
public int SamplePer3Secs { get; set; } = -1;

public double Percentage { get; set; } = -1d;
}
}
4 changes: 2 additions & 2 deletions src/SkyWalking.Abstractions/Config/TransportConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace SkyWalking.Config
[Config("SkyWalking", "Transport")]
public class TransportConfig
{
public int PendingSegmentLimit { get; set; } = 30000;
public int QueueSize { get; set; } = 30000;

/// <summary>
/// Flush Interval Millisecond
Expand All @@ -31,7 +31,7 @@ public class TransportConfig
/// <summary>
/// Data queued beyond this time will be discarded.
/// </summary>
public int PendingSegmentTimeout { get; set; } = 1000;
public int BatchSize { get; set; } = 3000;

public string ProtocolVersion { get; set; } = ProtocolVersions.V6;
}
Expand Down
Loading

0 comments on commit 2f24067

Please sign in to comment.