Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
CAP
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
CAP
Commits
886300ad
Commit
886300ad
authored
Apr 16, 2018
by
Liuhaoyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix some bug .
parent
af15d97d
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
200 additions
and
24 deletions
+200
-24
HostingDiagnosticListener.cs
...lking.AspNetCore/Diagnostics/HostingDiagnosticListener.cs
+6
-1
ServiceCollectionExtensions.cs
...king.AspNetCore/Extensions/ServiceCollectionExtensions.cs
+7
-2
SkyWalking.AspNetCore.csproj
src/SkyWalking.AspNetCore/SkyWalking.AspNetCore.csproj
+1
-0
SkyWalkingHostedService.cs
src/SkyWalking.AspNetCore/SkyWalkingHostedService.cs
+8
-3
TracingHttpClient.cs
src/SkyWalking.AspNetCore/TracingHttpClient.cs
+14
-0
TracingHttpHandler.cs
src/SkyWalking.AspNetCore/TracingHttpHandler.cs
+54
-0
TracingHttpMessageHandlerBuilder.cs
...SkyWalking.AspNetCore/TracingHttpMessageHandlerBuilder.cs
+69
-0
ContextCarrier.cs
src/SkyWalking.Core/Context/ContextCarrier.cs
+4
-3
ContextManager.cs
src/SkyWalking.Core/Context/ContextManager.cs
+3
-3
TraceSegment.cs
src/SkyWalking.Core/Context/Trace/TraceSegment.cs
+1
-1
TracingContext.cs
src/SkyWalking.Core/Context/TracingContext.cs
+4
-4
GrpcApplicationService.cs
src/SkyWalking.Core/Remote/GrpcApplicationService.cs
+20
-5
GrpcTraceSegmentService.cs
src/SkyWalking.Core/Remote/GrpcTraceSegmentService.cs
+1
-1
ComponentsDefine.cs
src/SkyWalking.NetworkProtocol.Trace/ComponentsDefine.cs
+8
-1
No files found.
src/SkyWalking.AspNetCore/Diagnostics/HostingDiagnosticListener.cs
View file @
886300ad
...
...
@@ -22,6 +22,7 @@ using Microsoft.Extensions.DiagnosticAdapter;
using
SkyWalking.Context
;
using
SkyWalking.Context.Tag
;
using
SkyWalking.Context.Trace
;
using
SkyWalking.NetworkProtocol.Trace
;
namespace
SkyWalking.AspNetCore.Diagnostics
{
...
...
@@ -48,7 +49,7 @@ namespace SkyWalking.AspNetCore.Diagnostics
var
httpRequestSpan
=
ContextManager
.
CreateEntrySpan
(
httpContext
.
Request
.
Path
,
carrier
);
httpRequestSpan
.
AsHttp
();
httpRequestSpan
.
SetComponent
(
"Asp.Net Core"
);
httpRequestSpan
.
SetComponent
(
ComponentsDefine
.
AspNetCore
);
Tags
.
Url
.
Set
(
httpRequestSpan
,
httpContext
.
Request
.
Path
);
Tags
.
HTTP
.
Method
.
Set
(
httpRequestSpan
,
httpContext
.
Request
.
Method
);
}
...
...
@@ -57,6 +58,10 @@ namespace SkyWalking.AspNetCore.Diagnostics
public
void
HttpRequestInStop
(
HttpContext
httpContext
)
{
var
httpRequestSpan
=
ContextManager
.
ActiveSpan
;
if
(
httpRequestSpan
==
null
)
{
return
;
}
var
statusCode
=
httpContext
.
Response
.
StatusCode
;
if
(
statusCode
>=
400
)
{
...
...
src/SkyWalking.AspNetCore/Extensions/ServiceCollectionExtensions.cs
View file @
886300ad
...
...
@@ -19,7 +19,9 @@
using
System
;
using
Microsoft.Extensions.Configuration
;
using
Microsoft.Extensions.DependencyInjection
;
using
Microsoft.Extensions.DependencyInjection.Extensions
;
using
Microsoft.Extensions.Hosting
;
using
Microsoft.Extensions.Http
;
using
SkyWalking.AspNetCore.Diagnostics
;
namespace
SkyWalking.AspNetCore
...
...
@@ -50,9 +52,12 @@ namespace SkyWalking.AspNetCore
throw
new
ArgumentNullException
(
nameof
(
services
));
}
services
.
AddSingleton
<
IHostedService
,
SkyWalkingHostedService
>();
services
.
AddSingleton
<
ITracingDiagnosticListener
,
HostingDiagnosticListener
>();
services
.
AddHttpClient
<
TracingHttpClient
>(
"sw-tracing"
);
services
.
AddSingleton
<
IHostedService
,
SkyWalkingHostedService
>();
services
.
TryAddSingleton
<
ITracingDiagnosticListener
,
HostingDiagnosticListener
>();
services
.
AddTransient
<
HttpMessageHandlerBuilder
,
TracingHttpMessageHandlerBuilder
>();
return
services
;
}
}
...
...
src/SkyWalking.AspNetCore/SkyWalking.AspNetCore.csproj
View file @
886300ad
...
...
@@ -7,6 +7,7 @@
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.1.0-preview2-final" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.1.0-preview2-final" />
<PackageReference Include="Microsoft.Extensions.DiagnosticAdapter" Version="2.1.0-preview2-final" />
<PackageReference Include="Microsoft.Extensions.Http" Version="2.1.0-preview2-final" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.1.0-preview2-final" />
<PackageReference Include="Microsoft.Extensions.Options" Version="2.1.0-preview2-final" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.1.0-preview2-final" />
...
...
src/SkyWalking.AspNetCore/SkyWalkingHostedService.cs
View file @
886300ad
...
...
@@ -32,6 +32,9 @@ namespace SkyWalking.AspNetCore
{
public
class
SkyWalkingHostedService
:
IHostedService
{
private
readonly
IEnumerable
<
ITracingDiagnosticListener
>
_tracingDiagnosticListeners
;
private
readonly
DiagnosticListener
_diagnosticListener
;
public
SkyWalkingHostedService
(
IOptions
<
SkyWalkingOptions
>
options
,
IHostingEnvironment
hostingEnvironment
,
IEnumerable
<
ITracingDiagnosticListener
>
tracingDiagnosticListeners
,
DiagnosticListener
diagnosticListener
)
{
...
...
@@ -48,19 +51,21 @@ namespace SkyWalking.AspNetCore
AgentConfig
.
ApplicationCode
=
options
.
Value
.
ApplicationCode
;
CollectorConfig
.
DirectServers
=
options
.
Value
.
DirectServers
;
foreach
(
var
tracingDiagnosticListener
in
tracingDiagnosticListeners
)
diagnosticListener
.
SubscribeWithAdapter
(
tracingDiagnosticListener
)
;
_tracingDiagnosticListeners
=
tracingDiagnosticListeners
;
_diagnosticListener
=
diagnosticListener
;
}
public
async
Task
StartAsync
(
CancellationToken
cancellationToken
)
{
await
GrpcChannelManager
.
Instance
.
ConnectAsync
();
await
ServiceManager
.
Instance
.
Initialize
();
foreach
(
var
tracingDiagnosticListener
in
_tracingDiagnosticListeners
)
_diagnosticListener
.
SubscribeWithAdapter
(
tracingDiagnosticListener
);
}
public
async
Task
StopAsync
(
CancellationToken
cancellationToken
)
{
GrpcChannelManager
.
Instance
.
ShutdownAsync
();
await
GrpcChannelManager
.
Instance
.
ShutdownAsync
();
ServiceManager
.
Instance
.
Dispose
();
}
}
...
...
src/SkyWalking.AspNetCore/TracingHttpClient.cs
0 → 100644
View file @
886300ad
using
System.Net.Http
;
namespace
SkyWalking.AspNetCore
{
public
class
TracingHttpClient
{
public
HttpClient
HttpClient
{
get
;
}
public
TracingHttpClient
(
HttpClient
httpClient
)
{
HttpClient
=
httpClient
;
}
}
}
\ No newline at end of file
src/SkyWalking.AspNetCore/TracingHttpHandler.cs
0 → 100644
View file @
886300ad
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.
*
*/
using
System.Net.Http
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
SkyWalking.Context
;
using
SkyWalking.Context.Tag
;
using
SkyWalking.Context.Trace
;
using
SkyWalking.NetworkProtocol.Trace
;
namespace
SkyWalking.AspNetCore
{
public
class
TracingHttpHandler
:
DelegatingHandler
{
public
TracingHttpHandler
()
{
InnerHandler
=
new
HttpClientHandler
();
}
protected
override
async
Task
<
HttpResponseMessage
>
SendAsync
(
HttpRequestMessage
request
,
CancellationToken
cancellationToken
)
{
var
contextCarrier
=
new
ContextCarrier
();
var
peer
=
$"
{
request
.
RequestUri
.
Host
}
:
{
request
.
RequestUri
.
Port
}
"
;
var
span
=
ContextManager
.
CreateExitSpan
(
request
.
RequestUri
.
ToString
(),
contextCarrier
,
peer
);
Tags
.
Url
.
Set
(
span
,
request
.
RequestUri
.
ToString
());
span
.
AsHttp
();
span
.
SetComponent
(
ComponentsDefine
.
HttpClient
);
Tags
.
HTTP
.
Method
.
Set
(
span
,
request
.
Method
.
ToString
());
foreach
(
var
item
in
contextCarrier
.
Items
)
request
.
Headers
.
Add
(
item
.
HeadKey
,
item
.
HeadValue
);
var
response
=
await
base
.
SendAsync
(
request
,
cancellationToken
);
Tags
.
StatusCode
.
Set
(
span
,
response
.
StatusCode
.
ToString
());
ContextManager
.
StopSpan
(
span
);
return
response
;
}
}
}
\ No newline at end of file
src/SkyWalking.AspNetCore/TracingHttpMessageHandlerBuilder.cs
0 → 100644
View file @
886300ad
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.
*
*/
using
System
;
using
System.Collections.Generic
;
using
System.Net.Http
;
using
Microsoft.Extensions.Http
;
namespace
SkyWalking.AspNetCore
{
internal
class
TracingHttpMessageHandlerBuilder
:
HttpMessageHandlerBuilder
{
private
readonly
TracingHttpHandler
_primaryHandler
=
new
TracingHttpHandler
();
private
string
_name
;
public
override
string
Name
{
get
=>
_name
;
set
{
if
(
value
==
null
)
{
throw
new
ArgumentNullException
(
nameof
(
value
));
}
_name
=
value
;
}
}
public
override
IList
<
DelegatingHandler
>
AdditionalHandlers
{
get
;
}
=
new
List
<
DelegatingHandler
>();
public
override
HttpMessageHandler
Build
()
{
if
(
PrimaryHandler
==
null
)
{
throw
new
InvalidOperationException
();
}
return
CreateHandlerPipeline
(
PrimaryHandler
,
AdditionalHandlers
);
}
public
override
HttpMessageHandler
PrimaryHandler
{
get
=>
_primaryHandler
;
set
{
if
(
value
!=
null
)
{
_primaryHandler
.
InnerHandler
=
value
;
}
}
}
}
}
\ No newline at end of file
src/SkyWalking.Core/Context/ContextCarrier.cs
View file @
886300ad
...
...
@@ -107,7 +107,7 @@ namespace SkyWalking.Context
public
string
PeerHost
{
get
=>
_peerHost
;
set
=>
_peerHost
=
value
;
set
=>
_peerHost
=
"#"
+
value
;
}
public
int
PeerId
...
...
@@ -137,8 +137,9 @@ namespace SkyWalking.Context
&&
_spanId
>
-
1
&&
_parentApplicationInstanceId
!=
DictionaryUtil
.
NullValue
&&
_entryApplicationInstanceId
!=
DictionaryUtil
.
NullValue
&&
string
.
IsNullOrEmpty
(
_parentOperationName
)
&&
string
.
IsNullOrEmpty
(
_entryOperationName
)
&&
!
string
.
IsNullOrEmpty
(
_peerHost
)
&&
!
string
.
IsNullOrEmpty
(
_parentOperationName
)
&&
!
string
.
IsNullOrEmpty
(
_entryOperationName
)
&&
_primaryDistributedTraceId
!=
null
;
}
}
...
...
src/SkyWalking.Core/Context/ContextManager.cs
View file @
886300ad
...
...
@@ -34,9 +34,9 @@ namespace SkyWalking.Context
/// </summary>
public
class
ContextManager
:
ITracingContextListener
,
IBootService
,
IIgnoreTracerContextListener
{
private
static
readonly
ThreadLocal
<
ITracerContext
>
_context
=
new
Thread
Local
<
ITracerContext
>();
private
static
readonly
AsyncLocal
<
ITracerContext
>
_context
=
new
Async
Local
<
ITracerContext
>();
private
static
ITracerContext
GetOrCreateContext
(
S
tring
operationName
,
bool
forceSampling
)
private
static
ITracerContext
GetOrCreateContext
(
s
tring
operationName
,
bool
forceSampling
)
{
var
context
=
_context
.
Value
;
if
(
context
==
null
)
...
...
@@ -49,7 +49,7 @@ namespace SkyWalking.Context
else
{
if
(!
DictionaryUtil
.
IsNull
(
RemoteDownstreamConfig
.
Agent
.
ApplicationId
)
&&
DictionaryUtil
.
IsNull
(
RemoteDownstreamConfig
.
Agent
.
ApplicationInstanceId
))
!
DictionaryUtil
.
IsNull
(
RemoteDownstreamConfig
.
Agent
.
ApplicationInstanceId
))
{
var
suffixIdx
=
operationName
.
LastIndexOf
(
'.'
);
if
(
suffixIdx
>
-
1
&&
AgentConfig
.
IgnoreSuffix
.
Contains
(
operationName
.
Substring
(
suffixIdx
)))
...
...
src/SkyWalking.Core/Context/Trace/TraceSegment.cs
View file @
886300ad
...
...
@@ -39,7 +39,7 @@ namespace SkyWalking.Context.Trace
public
IEnumerable
<
ITraceSegmentRef
>
Refs
=>
_refs
;
public
IEnumerable
<
DistributedTraceId
>
RelatedGlobalTraces
{
get
;
}
public
IEnumerable
<
DistributedTraceId
>
RelatedGlobalTraces
=>
_relatedGlobalTraces
.
GetRelatedGlobalTraces
();
public
ID
TraceSegmentId
{
get
;
}
...
...
src/SkyWalking.Core/Context/TracingContext.cs
View file @
886300ad
...
...
@@ -72,7 +72,7 @@ namespace SkyWalking.Context
}
var
refs
=
_segment
.
Refs
;
var
firstSpan
=
_activeSpanStacks
.
Fir
st
();
var
firstSpan
=
_activeSpanStacks
.
La
st
();
var
metaValue
=
GetMetaValue
(
refs
);
...
...
@@ -132,7 +132,7 @@ namespace SkyWalking.Context
public
string
GetReadableGlobalTraceId
()
{
return
_segment
.
RelatedGlobalTraces
.
First
()?.
ToString
();
return
_segment
.
RelatedGlobalTraces
.
First
OrDefault
()?.
ToString
();
}
/// <summary>
...
...
@@ -320,7 +320,7 @@ namespace SkyWalking.Context
snapshot
.
EntryOperationId
=
metaValue
.
operationId
;
}
var
parentSpan
=
_activeSpanStacks
.
Fir
st
();
var
parentSpan
=
_activeSpanStacks
.
La
st
();
if
(
DictionaryUtil
.
IsNull
(
parentSpan
.
OperationId
))
{
...
...
@@ -345,7 +345,7 @@ namespace SkyWalking.Context
}
else
{
var
span
=
_activeSpanStacks
.
Fir
st
();
var
span
=
_activeSpanStacks
.
La
st
();
return
(
span
.
OperationName
,
span
.
OperationId
,
_segment
.
ApplicationInstanceId
);
}
}
...
...
src/SkyWalking.Core/Remote/GrpcApplicationService.cs
View file @
886300ad
...
...
@@ -24,6 +24,7 @@ using System.Threading.Tasks;
using
SkyWalking.Boot
;
using
SkyWalking.Config
;
using
SkyWalking.Context
;
using
SkyWalking.Dictionarys
;
using
SkyWalking.NetworkProtocol
;
namespace
SkyWalking.Remote
...
...
@@ -37,9 +38,16 @@ namespace SkyWalking.Remote
var
application
=
new
Application
{
ApplicationCode
=
AgentConfig
.
ApplicationCode
};
var
applicationRegisterService
=
new
ApplicationRegisterService
.
ApplicationRegisterServiceClient
(
GrpcChannelManager
.
Instance
.
Channel
);
var
applicationMapping
=
await
applicationRegisterService
.
applicationCodeRegisterAsync
(
application
);
RemoteDownstreamConfig
.
Agent
.
ApplicationId
=
applicationMapping
.
Application
.
Value
;
var
applicationId
=
default
(
int
?);
while
(!
applicationId
.
HasValue
||
DictionaryUtil
.
IsNull
(
applicationId
.
Value
))
{
var
applicationMapping
=
await
applicationRegisterService
.
applicationCodeRegisterAsync
(
application
);
applicationId
=
applicationMapping
?.
Application
?.
Value
;
}
RemoteDownstreamConfig
.
Agent
.
ApplicationId
=
applicationId
.
Value
;
var
instanceDiscoveryService
=
new
InstanceDiscoveryService
.
InstanceDiscoveryServiceClient
(
GrpcChannelManager
.
Instance
.
Channel
);
...
...
@@ -63,14 +71,21 @@ namespace SkyWalking.Remote
var
applicationInstance
=
new
ApplicationInstance
{
ApplicationId
=
application
Mapping
.
Application
.
Value
,
ApplicationId
=
application
Id
.
Value
,
AgentUUID
=
agentUUID
,
RegisterTime
=
registerTime
,
Osinfo
=
osInfo
};
var
applicationInstanceMapping
=
await
instanceDiscoveryService
.
registerInstanceAsync
(
applicationInstance
);
RemoteDownstreamConfig
.
Agent
.
ApplicationInstanceId
=
applicationInstanceMapping
.
ApplicationInstanceId
;
var
applicationInstanceId
=
0
;
while
(
DictionaryUtil
.
IsNull
(
applicationInstanceId
))
{
var
applicationInstanceMapping
=
await
instanceDiscoveryService
.
registerInstanceAsync
(
applicationInstance
);
applicationInstanceId
=
applicationInstanceMapping
.
ApplicationInstanceId
;
}
RemoteDownstreamConfig
.
Agent
.
ApplicationInstanceId
=
applicationInstanceId
;
}
...
...
src/SkyWalking.Core/Remote/GrpcTraceSegmentService.cs
View file @
886300ad
...
...
@@ -29,7 +29,7 @@ namespace SkyWalking.Remote
new
TraceSegmentService
.
TraceSegmentServiceClient
(
GrpcChannelManager
.
Instance
.
Channel
);
using
(
var
asyncClientStreamingCall
=
traceSegmentService
.
collect
())
{
asyncClientStreamingCall
.
RequestStream
.
WriteAsync
(
segment
);
a
wait
a
syncClientStreamingCall
.
RequestStream
.
WriteAsync
(
segment
);
await
asyncClientStreamingCall
.
RequestStream
.
CompleteAsync
();
}
}
...
...
src/SkyWalking.NetworkProtocol.Trace/ComponentsDefine.cs
View file @
886300ad
...
...
@@ -17,12 +17,17 @@
*/
using
System.Collections.Generic
;
using
System.Runtime.InteropServices.ComTypes
;
namespace
SkyWalking.NetworkProtocol.Trace
{
public
class
ComponentsDefine
{
public
static
readonly
OfficialComponent
AspNetCore
=
new
OfficialComponent
(
1
,
"AspNetCore"
);
public
static
readonly
OfficialComponent
HttpClient
=
new
OfficialComponent
(
2
,
"HttpClient"
);
public
static
readonly
OfficialComponent
AspNetCore
=
new
OfficialComponent
(
30
,
"AspNetCore"
);
public
static
readonly
OfficialComponent
EntityFrameworkCore
=
new
OfficialComponent
(
31
,
"EntityFrameworkCore"
);
private
static
readonly
ComponentsDefine
_instance
=
new
ComponentsDefine
();
...
...
@@ -39,6 +44,8 @@ namespace SkyWalking.NetworkProtocol.Trace
private
ComponentsDefine
()
{
_components
=
new
Dictionary
<
int
,
string
>();
AddComponent
(
AspNetCore
);
AddComponent
(
EntityFrameworkCore
);
}
private
void
AddComponent
(
OfficialComponent
component
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment