-
Notifications
You must be signed in to change notification settings - Fork 108
add fastapi #180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
add fastapi #180
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
f9155b4
add plugin for mysqlclient
6cd0ceb
add plugin for mysqlclient
11094d6
add plugin for mysqlclient
73b7021
add plugin for mysqlclient
4a65c52
add plugin for mysqlclient
c29afcb
unit test edit
da31afe
Merge branch 'master' into master
wu-sheng 0ad52ba
edit unit test
7f3a670
edit unit test
131aa98
edit unit test
a3cfd02
Update skywalking/plugins/sw_mysqlclient.py
kezhenxu94 75999dc
edit unit test
0d4816b
Merge remote-tracking branch 'origin/master'
6cddcf0
add component
e90f5b9
Update tests/plugin/data/sw_mysqlclient/services/provider.py
kezhenxu94 d2affac
Minor changes
kezhenxu94 77408a5
Update Plugins.md
kezhenxu94 0660b6a
add fastapi
6aa50d9
Merge remote-tracking branch 'origin/master'
4fa7ad2
Merge branch 'master' into master
kezhenxu94 6c3f7bf
add fastapi
4a9b77b
add fastapi
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| # | ||
| # 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. | ||
| # | ||
|
|
||
| from starlette.types import ASGIApp, Receive, Scope, Send | ||
| from skywalking import Layer, Component, config | ||
| from skywalking.trace.carrier import Carrier | ||
| from skywalking.trace.context import get_context, NoopContext | ||
| from skywalking.trace.span import NoopSpan | ||
| from skywalking.trace.tags import TagHttpMethod, TagHttpURL, TagHttpStatusCode, TagHttpParams | ||
|
|
||
| link_vector = ['https://flask.palletsprojects.com'] | ||
| support_matrix = { | ||
| 'flask': { | ||
| '>=3.6': ['1.1', '2.0'] # 1.1 to be removed in near future | ||
| } | ||
| } | ||
| note = """""" | ||
|
|
||
|
|
||
| def install(): | ||
| from fastapi import routing | ||
| from fastapi.routing import APIRoute | ||
|
|
||
| _handle = APIRoute.handle | ||
|
|
||
| def params_tostring(params): | ||
| return '\n'.join([f"{k}=[{','.join(params.getlist(k))}]" for k, _ in params.items()]) | ||
|
|
||
| async def _sw_handle(self, scope: Scope, receive: Receive, send: Send): | ||
| from starlette.requests import Request | ||
| req = Request(scope, receive=receive, send=send) | ||
| carrier = Carrier() | ||
| method = req.method | ||
|
|
||
| for item in carrier: | ||
| if item.key.capitalize() in req.headers: | ||
| item.val = req.headers[item.key.capitalize()] | ||
|
|
||
| span = NoopSpan(NoopContext()) if config.ignore_http_method_check(method) \ | ||
| else get_context().new_entry_span(op=dict(scope)["path"], carrier=carrier, inherit=Component.General) | ||
|
|
||
| with span: | ||
| span.layer = Layer.Http | ||
| span.component = Component.Flask | ||
| span.peer = f"{req.client.host}:{req.client.port}" | ||
| span.tag(TagHttpMethod(method)) | ||
| span.tag(TagHttpURL(req.url._url.split('?')[0])) | ||
| if config.fastapi_collect_http_params and req.values: | ||
| span.tag(TagHttpParams(params_tostring(req.values)[0:config.http_params_length_threshold])) | ||
| res = await _handle(self, scope, receive, send) | ||
| # if isawaitable(resp): | ||
| # result = await resp | ||
| # if resp.status_code >= 400: | ||
| # span.error_occurred = True | ||
|
|
||
| # span.tag(TagHttpStatusCode(resp.status_code)) | ||
| return res | ||
|
|
||
| APIRoute.handle = _sw_handle | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should have an individual component for FastAPI?