-
Notifications
You must be signed in to change notification settings - Fork 105
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
Add Neo4j plugin. #312
Add Neo4j plugin. #312
Changes from all commits
7c52087
0f53b31
e9631c9
3ed4b96
e425170
7edd476
822541b
c6ae90d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,96 @@ | ||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||
# 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. | ||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
import json | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
from skywalking import Layer, Component, config | ||||||||||||||||||||||||||
from skywalking.trace.context import get_context | ||||||||||||||||||||||||||
from skywalking.trace.tags import TagDbType, TagDbInstance, TagDbStatement, TagDbSqlParameters | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
link_vector = ['https://neo4j.com/docs/python-manual/5/'] | ||||||||||||||||||||||||||
support_matrix = { | ||||||||||||||||||||||||||
'neo4j': { | ||||||||||||||||||||||||||
'>=3.7': ['5.*'], | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
note = """The Neo4j plugin integrates neo4j python driver 5.x.x versions which | ||||||||||||||||||||||||||
support both Neo4j 5 and 4.4 DBMS.""" | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
def install(): | ||||||||||||||||||||||||||
from neo4j import AsyncSession, Session | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reportMissingImports: Import "neo4j" could not be resolved ❗❗ 7 similar findings have been found in this PR 🔎 Expand here to view all instances of this finding
Visit the Lift Web Console to find more details in your report. ℹ️ Expand to see all @sonatype-lift commandsYou can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.
Note: When talking to LiftBot, you need to refresh the page to see its response. |
||||||||||||||||||||||||||
from neo4j._sync.work.transaction import TransactionBase | ||||||||||||||||||||||||||
from neo4j._async.work.transaction import AsyncTransactionBase | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
_session_run = Session.run | ||||||||||||||||||||||||||
_async_session_run = AsyncSession.run | ||||||||||||||||||||||||||
_transaction_run = TransactionBase.run | ||||||||||||||||||||||||||
_async_transaction_run = AsyncTransactionBase.run | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
def _archive_span(span, database, query, parameters, **kwargs): | ||||||||||||||||||||||||||
span.layer = Layer.Database | ||||||||||||||||||||||||||
span.tag(TagDbType('Neo4j')) | ||||||||||||||||||||||||||
span.tag(TagDbInstance(database or '')) | ||||||||||||||||||||||||||
span.tag(TagDbStatement(query)) | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
parameters = dict(parameters or {}, **kwargs) | ||||||||||||||||||||||||||
if config.plugin_sql_parameters_max_length and parameters: | ||||||||||||||||||||||||||
parameter = json.dumps(parameters, ensure_ascii=False) | ||||||||||||||||||||||||||
max_len = config.plugin_sql_parameters_max_length | ||||||||||||||||||||||||||
parameter = f'{parameter[0:max_len]}...' if len( | ||||||||||||||||||||||||||
parameter) > max_len else parameter | ||||||||||||||||||||||||||
span.tag(TagDbSqlParameters(f'[{parameter}]')) | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
def get_peer(address): | ||||||||||||||||||||||||||
return f'{address.host}:{address.port}' | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
def _sw_session_run(self, query, parameters, **kwargs): | ||||||||||||||||||||||||||
with get_context().new_exit_span( | ||||||||||||||||||||||||||
op='Neo4j/Session/run', | ||||||||||||||||||||||||||
peer=get_peer(self._pool.address), | ||||||||||||||||||||||||||
component=Component.Neo4j) as span: | ||||||||||||||||||||||||||
_archive_span(span, self._config.database, query, parameters, **kwargs) | ||||||||||||||||||||||||||
return _session_run(self, query, parameters, **kwargs) | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
def _sw_transaction_run(self, query, parameters=None, **kwargs): | ||||||||||||||||||||||||||
with get_context().new_exit_span( | ||||||||||||||||||||||||||
op='Neo4j/Transaction/run', | ||||||||||||||||||||||||||
peer=get_peer(self._connection.unresolved_address), | ||||||||||||||||||||||||||
component=Component.Neo4j) as span: | ||||||||||||||||||||||||||
_archive_span(span, self._database, query, parameters, **kwargs) | ||||||||||||||||||||||||||
return _transaction_run(self, query, parameters, **kwargs) | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
async def _sw_async_session_run(self, query, parameters, **kwargs): | ||||||||||||||||||||||||||
with get_context().new_exit_span( | ||||||||||||||||||||||||||
op='Neo4j/AsyncSession/run', | ||||||||||||||||||||||||||
peer=get_peer(self._pool.address), | ||||||||||||||||||||||||||
component=Component.Neo4j) as span: | ||||||||||||||||||||||||||
_archive_span(span, self._config.database, query, parameters, **kwargs) | ||||||||||||||||||||||||||
return await _async_session_run(self, query, parameters, **kwargs) | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
async def _sw_async_transaction_run(self, query, parameters, **kwargs): | ||||||||||||||||||||||||||
with get_context().new_exit_span( | ||||||||||||||||||||||||||
op='Neo4j/AsyncTransaction/run', | ||||||||||||||||||||||||||
peer=get_peer(self._connection.unresolved_address), | ||||||||||||||||||||||||||
component=Component.Neo4j) as span: | ||||||||||||||||||||||||||
_archive_span(span, self._database, query, parameters, **kwargs) | ||||||||||||||||||||||||||
return await _async_transaction_run(self, query, parameters, **kwargs) | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
Session.run = _sw_session_run | ||||||||||||||||||||||||||
AsyncSession.run = _sw_async_session_run | ||||||||||||||||||||||||||
TransactionBase.run = _sw_transaction_run | ||||||||||||||||||||||||||
AsyncTransactionBase.run = _sw_async_transaction_run |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# | ||
# 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. | ||
# |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# | ||
# 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. | ||
# | ||
|
||
version: '2.1' | ||
|
||
services: | ||
collector: | ||
extends: | ||
service: collector | ||
file: ../../docker-compose.base.yml | ||
|
||
neo4j: | ||
image: neo4j:4.4-community | ||
hostname: neo4j | ||
ports: | ||
- 7687:7687 | ||
environment: | ||
- NEO4J_dbms_security_auth__enabled=false | ||
healthcheck: | ||
test: ["CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/7687"] | ||
interval: 5s | ||
timeout: 60s | ||
retries: 120 | ||
networks: | ||
- beyond | ||
|
||
provider: | ||
extends: | ||
service: agent | ||
file: ../../docker-compose.base.yml | ||
ports: | ||
- 9091:9091 | ||
volumes: | ||
- .:/app | ||
command: ['bash', '-c', 'pip3 install uvicorn && pip3 install fastapi && pip3 install -r /app/requirements.txt && sw-python run python3 /app/services/provider.py'] | ||
depends_on: | ||
collector: | ||
condition: service_healthy | ||
neo4j: | ||
condition: service_healthy | ||
healthcheck: | ||
test: ["CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/9091"] | ||
interval: 5s | ||
timeout: 60s | ||
retries: 120 | ||
environment: | ||
SW_AGENT_NAME: provider | ||
SW_AGENT_LOGGING_LEVEL: DEBUG | ||
SW_PLUGIN_SQL_PARAMETERS_MAX_LENGTH: 512 | ||
|
||
consumer: | ||
extends: | ||
service: agent | ||
file: ../../docker-compose.base.yml | ||
ports: | ||
- 9090:9090 | ||
volumes: | ||
- .:/app | ||
command: ['bash', '-c', 'pip3 install uvicorn && pip3 install fastapi && pip3 install -r /app/requirements.txt && sw-python run python3 /app/services/consumer.py'] | ||
depends_on: | ||
collector: | ||
condition: service_healthy | ||
provider: | ||
condition: service_healthy | ||
environment: | ||
SW_AGENT_NAME: consumer | ||
SW_AGENT_LOGGING_LEVEL: DEBUG | ||
|
||
networks: | ||
beyond: |
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.
E0401: Unable to import 'neo4j'
❗❗ 7 similar findings have been found in this PR
🔎 Expand here to view all instances of this finding
Visit the Lift Web Console to find more details in your report.
ℹ️ Expand to see all @sonatype-lift commands
You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.
@sonatype-lift ignore
@sonatype-lift ignoreall
@sonatype-lift exclude <file|issue|path|tool>
file|issue|path|tool
from Lift findings by updating your config.toml fileNote: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.