├── LICENSE
├── README.md
├── code-of-conduct.md
├── docs
├── README.md
├── databases
│ ├── README.md
│ ├── mariadb
│ │ └── README.md
│ ├── mysql
│ │ └── README.md
│ └── postgresql
│ │ └── README.md
├── faq
│ └── README.md
├── images
│ ├── activerecord_marginalia-logo.png
│ ├── aws-logo.png
│ ├── cloud-sql-card.png
│ ├── django-logo.png
│ ├── express_js-logo.png
│ ├── flask-logo.png
│ ├── gcp-logo.png
│ ├── hibernate-logo.png
│ ├── java-logo.png
│ ├── knex-logo.png
│ ├── locally-logo.png
│ ├── mariadb-logo.png
│ ├── mysql-logo.png
│ ├── nodejs-logo.png
│ ├── postgresql-logo.png
│ ├── psycopg2-logo.png
│ ├── python-logo.png
│ ├── ruby-logo.png
│ ├── sequelize-logo.png
│ ├── spring-logo.png
│ ├── sqlalchemy-logo.png
│ ├── sqlcommenter_logo.png
│ └── sqlite-logo.png
├── java
│ ├── README.md
│ ├── hibernate
│ │ └── README.md
│ └── spring
│ │ └── README.md
├── node-js
│ ├── README.md
│ ├── express
│ │ └── README.md
│ ├── knex
│ │ └── README.md
│ └── sequelize
│ │ └── README.md
├── python
│ ├── README.md
│ ├── SQLAlchemy
│ │ └── README.md
│ ├── django
│ │ ├── README.md
│ │ ├── aws.md
│ │ ├── gcp.md
│ │ └── local.md
│ └── psycopg2
│ │ └── README.md
├── ruby
│ ├── README.md
│ └── ruby-on-rails
│ │ └── README.md
└── specifications
│ └── README.md
├── java
└── sqlcommenter-java
│ ├── .gitignore
│ ├── README.md
│ ├── build.gradle
│ ├── gradle
│ └── wrapper
│ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ ├── scripts
│ └── travis_script
│ ├── settings.gradle
│ └── src
│ ├── main
│ └── java
│ │ └── io
│ │ └── opentelemetry
│ │ └── sqlcommenter
│ │ ├── interceptors
│ │ └── SpringSQLCommenterInterceptor.java
│ │ ├── schibernate
│ │ └── SCHibernate.java
│ │ └── threadlocalstorage
│ │ ├── SpanContextMetadata.java
│ │ └── State.java
│ └── test
│ ├── java
│ └── io
│ │ └── opentelemetry
│ │ └── sqlcommenter
│ │ ├── interceptors
│ │ └── SpringSQLCommenterInterceptorTest.java
│ │ ├── schibernate
│ │ └── SCHibernateTest.java
│ │ ├── spring
│ │ └── backend
│ │ │ ├── JpaTransactionManagerConfiguration.java
│ │ │ ├── JpaTransactionManagerTest.java
│ │ │ ├── dao
│ │ │ ├── PostRepository.java
│ │ │ └── TagRepository.java
│ │ │ ├── domain
│ │ │ ├── Post.java
│ │ │ └── Tag.java
│ │ │ └── service
│ │ │ ├── ForumService.java
│ │ │ └── ForumServiceImpl.java
│ │ ├── threadlocalstorage
│ │ ├── StateTest.java
│ │ └── ThreadLocalStorageTest.java
│ │ └── util
│ │ └── SCHibernateWrapper.java
│ └── resources
│ ├── META-INF
│ └── jdbc-hsqldb.properties
│ └── logback-test.xml
├── nodejs
└── sqlcommenter-nodejs
│ ├── .gitignore
│ ├── README.md
│ ├── packages
│ ├── sqlcommenter-knex
│ │ ├── LICENSE
│ │ ├── README.md
│ │ ├── hooks.js
│ │ ├── index.js
│ │ ├── package-lock.json
│ │ ├── package.json
│ │ ├── provider
│ │ │ ├── index.js
│ │ │ ├── opencensus.js
│ │ │ └── opentelemetry.js
│ │ ├── test
│ │ │ ├── comment.test.js
│ │ │ ├── express.test.js
│ │ │ ├── rewiremock.js
│ │ │ └── unit
│ │ │ │ ├── provider.js
│ │ │ │ └── util.js
│ │ └── util.js
│ └── sqlcommenter-sequelize
│ │ ├── LICENSE
│ │ ├── README.md
│ │ ├── hooks.js
│ │ ├── index.js
│ │ ├── package-lock.json
│ │ ├── package.json
│ │ ├── provider
│ │ ├── index.js
│ │ ├── opencensus.js
│ │ └── opentelemetry.js
│ │ ├── test
│ │ ├── comment.test.js
│ │ ├── express.test.js
│ │ ├── rewiremock.js
│ │ └── unit
│ │ │ ├── provider.js
│ │ │ └── util.js
│ │ └── util.js
│ └── samples
│ └── express-opentelemetry
│ ├── README.md
│ ├── knexConnection.js
│ ├── knexServer.js
│ ├── package-lock.json
│ ├── package.json
│ ├── sequelizeModels.js
│ ├── sequelizeServer.js
│ └── util.js
├── package_it.sh
├── python
├── samples
│ ├── .gitignore
│ ├── README.md
│ ├── psycopgy_opentelemetry_sample.py
│ └── requirements.txt
└── sqlcommenter-python
│ ├── .gitignore
│ ├── README.md
│ ├── opentelemetry
│ ├── __init__.py
│ └── sqlcommenter
│ │ ├── __init__.py
│ │ ├── django
│ │ ├── __init__.py
│ │ └── middleware.py
│ │ ├── flask.py
│ │ ├── opencensus.py
│ │ ├── opentelemetry.py
│ │ ├── psycopg2
│ │ ├── __init__.py
│ │ └── extension.py
│ │ ├── sqlalchemy
│ │ ├── __init__.py
│ │ └── executor.py
│ │ └── version.py
│ ├── runtests.py
│ ├── setup.cfg
│ ├── setup.py
│ ├── tests
│ ├── __init__.py
│ ├── compat.py
│ ├── django
│ │ ├── __init__.py
│ │ ├── app_urls.py
│ │ ├── models.py
│ │ ├── settings.py
│ │ ├── tests.py
│ │ ├── urls.py
│ │ └── views.py
│ ├── flask
│ │ ├── __init__.py
│ │ ├── app.py
│ │ └── tests.py
│ ├── generic
│ │ ├── __init__.py
│ │ ├── test_generate_sql_comment.py
│ │ ├── test_opencensus.py
│ │ └── test_opentelemetry.py
│ ├── opencensus_mock.py
│ ├── opentelemetry_mock.py
│ ├── psycopg2
│ │ ├── __init__.py
│ │ └── tests.py
│ ├── sqlalchemy
│ │ ├── __init__.py
│ │ └── tests.py
│ └── tests.py
│ └── tox.ini
└── ruby
└── sqlcommenter-ruby
├── .gitignore
├── README.md
├── marginalia-opencensus
├── .gitignore
├── .rspec
├── .rubocop.yml
├── .travis.yml
├── Gemfile
├── README.md
├── Rakefile
├── bin
│ ├── console
│ ├── rails
│ └── setup
├── lib
│ ├── marginalia-opencensus.rb
│ └── marginalia
│ │ ├── opencensus.rb
│ │ └── opencensus
│ │ ├── marginalia_components.rb
│ │ └── version.rb
├── marginalia-opencensus.gemspec
├── rubocop.gemfile
└── spec
│ ├── gemfiles
│ ├── rails_5_2.gemfile
│ ├── rails_6_0.gemfile
│ └── rubocop.gemfile
│ ├── internal
│ ├── Rakefile
│ ├── app
│ │ └── controllers
│ │ │ └── internal_app_controller.rb
│ ├── config
│ │ ├── application.rb
│ │ ├── boot.rb
│ │ ├── database.yml
│ │ ├── environment.rb
│ │ └── routes.rb
│ ├── db
│ │ ├── .gitignore
│ │ └── schema.rb
│ ├── log
│ │ └── .gitignore
│ └── public
│ │ └── favicon.ico
│ ├── marginalia
│ └── opencensus
│ │ ├── integration_spec.rb
│ │ └── marginalia_comment_components_spec.rb
│ └── spec_helper.rb
├── sqlcommenter_rails
├── .gitignore
├── .rspec
├── .rubocop.yml
├── .travis.yml
├── Gemfile
├── README.md
├── Rakefile
├── bin
│ ├── console
│ ├── rails
│ └── setup
├── lib
│ ├── sqlcommenter_rails.rb
│ └── sqlcommenter_rails
│ │ ├── marginalia_components.rb
│ │ └── version.rb
├── rubocop.gemfile
├── shared.gemfile
├── spec
│ ├── gemfiles
│ │ ├── rails_5_2.gemfile
│ │ ├── rails_6_0.gemfile
│ │ └── rubocop.gemfile
│ ├── internal
│ │ ├── Rakefile
│ │ ├── app
│ │ │ └── controllers
│ │ │ │ └── internal_app_controller.rb
│ │ ├── config
│ │ │ ├── application.rb
│ │ │ ├── boot.rb
│ │ │ ├── database.yml
│ │ │ ├── environment.rb
│ │ │ └── routes.rb
│ │ ├── db
│ │ │ ├── .gitignore
│ │ │ └── schema.rb
│ │ ├── log
│ │ │ └── .gitignore
│ │ └── public
│ │ │ └── favicon.ico
│ ├── spec_helper.rb
│ └── sqlcommenter_rails
│ │ ├── integration_spec.rb
│ │ └── marginalia_comment_components_spec.rb
└── sqlcommenter_rails.gemspec
└── sqlcommenter_rails_demo
├── .gitignore
├── .ruby-version
├── Gemfile
├── Gemfile.lock
├── README.md
├── Rakefile
├── app
├── controllers
│ ├── application_controller.rb
│ └── posts_controller.rb
└── models
│ ├── application_record.rb
│ └── post.rb
├── bin
├── bundle
├── rails
├── rake
├── setup
└── spring
├── config.ru
├── config
├── application.rb
├── boot.rb
├── cable.yml
├── credentials.yml.enc
├── database.yml
├── environment.rb
├── environments
│ ├── development.rb
│ ├── production.rb
│ └── test.rb
├── puma.rb
├── routes.rb
├── spring.rb
└── storage.yml
├── db
├── migrate
│ └── 20190608153219_create_posts.rb
└── schema.rb
├── log
└── .keep
├── test
├── controllers
│ └── posts_controller_test.rb
├── fixtures
│ └── posts.yml
└── test_helper.rb
└── tmp
└── .keep
/README.md:
--------------------------------------------------------------------------------
1 | SQLCommenter components for various languages
2 |
3 | **This repository is the temporary repository toward the migration to `contrib/instrumentation` repositories for each languages. See details in these tickets. [[1](https://github.com/open-telemetry/community/issues/783)][[2](https://github.com/open-telemetry/opentelemetry-java-contrib/issues/205)]**
4 |
5 | [Documentation](https://google.github.io/sqlcommenter/)
6 |
7 | Contains all the various `sqlcommenter-*` implementations.
8 |
9 | - [X] [Python](python/sqlcommenter-python/README.md)
10 | - [X] [django](python/sqlcommenter-python/README.md#django)
11 | - [X] [psycopg2](python/sqlcommenter-python/README.md#psycopg2)
12 | - [X] [sqlalchemy](python/sqlcommenter-python/README.md#sqlalchemy)
13 | - [X] [Java](java/sqlcommenter-java/README.md)
14 | - [X] [Hibernate](java/sqlcommenter-java/README.md#hibernate)
15 | - [X] [Spring+Hibernate](java/sqlcommenter-java/README.md#spring-hibernate)
16 | - [X] Ruby
17 | - [X] [Rails](ruby/sqlcommenter-ruby/sqlcommenter_rails/README.md)
18 | - [X] [Node.js](nodejs/sqlcommenter-nodejs/README.md)
19 | - [X] [Knex.js](nodejs/sqlcommenter-nodejs/packages/sqlcommenter-knex/README.md)
20 | - [X] [Sequelize.js](nodejs/sqlcommenter-nodejs/packages/sqlcommenter-sequelize/README.md)
21 |
--------------------------------------------------------------------------------
/code-of-conduct.md:
--------------------------------------------------------------------------------
1 | # OpenTelemetry Community Code of Conduct
2 |
3 | OpenTelemetry follows the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/master/code-of-conduct.md).
--------------------------------------------------------------------------------
/docs/databases/README.md:
--------------------------------------------------------------------------------
1 | # Databases
2 |
3 | In order to examine the results of [sqlcommenter](../), we'll need
4 | to examine query logs on the database. Below are some guides to help make this happen:
5 |
6 |
7 | [](postgresql)
8 |
9 | [](mysql)
10 |
11 | [](mariadb)
12 |
13 | [](https://sqlite.org/cli.html)
14 |
15 | [](https://cloud.google.com/sql/)
16 |
17 |
18 |
39 |
--------------------------------------------------------------------------------
/docs/databases/mariadb/README.md:
--------------------------------------------------------------------------------
1 | # MariaDB
2 |
3 | 
4 |
5 | If you host your own instance of MariaDB, you can run it with logs to examine statements by following the guide at
6 | [Query log output destination](https://mariadb.com/kb/en/library/general-query-log/#choosing-the-general-query-log-output-destination)
7 |
8 | ## References
9 |
10 | Resource|URL
11 | ---|---
12 | Log output|
13 | MariaDB Docker|
--------------------------------------------------------------------------------
/docs/databases/mysql/README.md:
--------------------------------------------------------------------------------
1 | # MySQL
2 |
3 | 
4 |
5 | If you host your own instance of MySQL, you can run it with logs to examine statements by following the guide at:
6 |
7 | ## References
8 |
9 | Guide|URL
10 | ---|---
11 | Running MySQL locally/System variables: log output|
12 | MySQL Docker installation with logs|
--------------------------------------------------------------------------------
/docs/databases/postgresql/README.md:
--------------------------------------------------------------------------------
1 | # Postgresql
2 |
3 | 
4 |
5 | If you host your own instance of Postgresql, you can run it with logs to examine statements by following the guide at
6 | [Runtime config logging](https://www.postgresql.org/docs/11/runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-WHERE)
7 |
8 | i.e. on macOS, edit `/usr/local/var/postgres/postgresql.conf` and set `log_destination` to `'stderr'` as per:
9 | ```python
10 | #------------------------------------------------------------------------------
11 | # REPORTING AND LOGGING
12 | #------------------------------------------------------------------------------
13 |
14 | # - Where to Log -
15 |
16 | log_destination = 'stderr' # Valid values are combinations of
17 | # stderr, csvlog, syslog, and eventlog,
18 | # depending on platform. csvlog
19 | # requires logging_collector to be on.
20 | ```
21 |
22 | and then when run as per
23 | ```shell
24 | $ PGDATA=/usr/local/var/postgres postgres
25 | ```
26 |
27 | produces such output
28 | ```shell
29 | 2019-05-31 16:27:27.482 PDT [19175] LOG: listening on IPv4 address "127.0.0.1", port 5432
30 | 2019-05-31 16:27:27.482 PDT [19175] LOG: listening on IPv6 address "::1", port 5432
31 | 2019-05-31 16:27:27.482 PDT [19175] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"
32 | 2019-05-31 16:27:27.503 PDT [19176] LOG: database system was shut down at 2019-05-31 16:27:06 PDT
33 | 2019-05-31 16:27:27.508 PDT [19175] LOG: database system is ready to accept connections
34 | 2019-05-31 16:27:31.190 PDT [19183] LOG: statement: SET TIME ZONE 'UTC'
35 | 2019-05-31 16:27:31.195 PDT [19183] LOG: statement: INSERT INTO "polls_question"
36 | ("question_text", "pub_date") VALUES ('Wassup?', '2019-05-31T23:27:31.175952+00:00'::timestamptz)
37 | RETURNING "polls_question"."id" /*controller='index',db_driver='django.db.backends.postgresql',
38 | framework='django%3A2.2.1',route='%5Epolls/%24'*/
39 | ```
40 |
41 | ## References
42 |
43 | Resource|URL
44 | ---|---
45 | Runtime config logging|
--------------------------------------------------------------------------------
/docs/images/activerecord_marginalia-logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-telemetry/opentelemetry-sqlcommenter/2f8841add68358069ebf1c0ee560ab3e98a59aa9/docs/images/activerecord_marginalia-logo.png
--------------------------------------------------------------------------------
/docs/images/aws-logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-telemetry/opentelemetry-sqlcommenter/2f8841add68358069ebf1c0ee560ab3e98a59aa9/docs/images/aws-logo.png
--------------------------------------------------------------------------------
/docs/images/cloud-sql-card.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-telemetry/opentelemetry-sqlcommenter/2f8841add68358069ebf1c0ee560ab3e98a59aa9/docs/images/cloud-sql-card.png
--------------------------------------------------------------------------------
/docs/images/django-logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-telemetry/opentelemetry-sqlcommenter/2f8841add68358069ebf1c0ee560ab3e98a59aa9/docs/images/django-logo.png
--------------------------------------------------------------------------------
/docs/images/express_js-logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-telemetry/opentelemetry-sqlcommenter/2f8841add68358069ebf1c0ee560ab3e98a59aa9/docs/images/express_js-logo.png
--------------------------------------------------------------------------------
/docs/images/flask-logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-telemetry/opentelemetry-sqlcommenter/2f8841add68358069ebf1c0ee560ab3e98a59aa9/docs/images/flask-logo.png
--------------------------------------------------------------------------------
/docs/images/gcp-logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-telemetry/opentelemetry-sqlcommenter/2f8841add68358069ebf1c0ee560ab3e98a59aa9/docs/images/gcp-logo.png
--------------------------------------------------------------------------------
/docs/images/hibernate-logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-telemetry/opentelemetry-sqlcommenter/2f8841add68358069ebf1c0ee560ab3e98a59aa9/docs/images/hibernate-logo.png
--------------------------------------------------------------------------------
/docs/images/java-logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-telemetry/opentelemetry-sqlcommenter/2f8841add68358069ebf1c0ee560ab3e98a59aa9/docs/images/java-logo.png
--------------------------------------------------------------------------------
/docs/images/knex-logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-telemetry/opentelemetry-sqlcommenter/2f8841add68358069ebf1c0ee560ab3e98a59aa9/docs/images/knex-logo.png
--------------------------------------------------------------------------------
/docs/images/locally-logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-telemetry/opentelemetry-sqlcommenter/2f8841add68358069ebf1c0ee560ab3e98a59aa9/docs/images/locally-logo.png
--------------------------------------------------------------------------------
/docs/images/mariadb-logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-telemetry/opentelemetry-sqlcommenter/2f8841add68358069ebf1c0ee560ab3e98a59aa9/docs/images/mariadb-logo.png
--------------------------------------------------------------------------------
/docs/images/mysql-logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-telemetry/opentelemetry-sqlcommenter/2f8841add68358069ebf1c0ee560ab3e98a59aa9/docs/images/mysql-logo.png
--------------------------------------------------------------------------------
/docs/images/nodejs-logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-telemetry/opentelemetry-sqlcommenter/2f8841add68358069ebf1c0ee560ab3e98a59aa9/docs/images/nodejs-logo.png
--------------------------------------------------------------------------------
/docs/images/postgresql-logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-telemetry/opentelemetry-sqlcommenter/2f8841add68358069ebf1c0ee560ab3e98a59aa9/docs/images/postgresql-logo.png
--------------------------------------------------------------------------------
/docs/images/psycopg2-logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-telemetry/opentelemetry-sqlcommenter/2f8841add68358069ebf1c0ee560ab3e98a59aa9/docs/images/psycopg2-logo.png
--------------------------------------------------------------------------------
/docs/images/python-logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-telemetry/opentelemetry-sqlcommenter/2f8841add68358069ebf1c0ee560ab3e98a59aa9/docs/images/python-logo.png
--------------------------------------------------------------------------------
/docs/images/ruby-logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-telemetry/opentelemetry-sqlcommenter/2f8841add68358069ebf1c0ee560ab3e98a59aa9/docs/images/ruby-logo.png
--------------------------------------------------------------------------------
/docs/images/sequelize-logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-telemetry/opentelemetry-sqlcommenter/2f8841add68358069ebf1c0ee560ab3e98a59aa9/docs/images/sequelize-logo.png
--------------------------------------------------------------------------------
/docs/images/spring-logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-telemetry/opentelemetry-sqlcommenter/2f8841add68358069ebf1c0ee560ab3e98a59aa9/docs/images/spring-logo.png
--------------------------------------------------------------------------------
/docs/images/sqlalchemy-logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-telemetry/opentelemetry-sqlcommenter/2f8841add68358069ebf1c0ee560ab3e98a59aa9/docs/images/sqlalchemy-logo.png
--------------------------------------------------------------------------------
/docs/images/sqlcommenter_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-telemetry/opentelemetry-sqlcommenter/2f8841add68358069ebf1c0ee560ab3e98a59aa9/docs/images/sqlcommenter_logo.png
--------------------------------------------------------------------------------
/docs/images/sqlite-logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-telemetry/opentelemetry-sqlcommenter/2f8841add68358069ebf1c0ee560ab3e98a59aa9/docs/images/sqlite-logo.png
--------------------------------------------------------------------------------
/docs/java/README.md:
--------------------------------------------------------------------------------
1 | # Java
2 | - [Java](#java)
3 | - [Introduction](#introduction)
4 | - [Integrations](#integrations)
5 | - [Installing it](#installing-it)
6 | - [From source](#from-source)
7 | - [Building it](#building-it)
8 | - [Verify installation](#verify-installation)
9 | - [Tests](#tests)
10 |
11 | ## Introduction
12 | sqlcommenter-java is the implementation of [sqlcommenter](../) in the Java programming language.
13 |
14 |
15 | ## Integrations
16 |
17 | sqlcommenter-java provides support for the following plugins/ORMs:
18 |
19 | [](hibernate)
20 |
21 | [](spring)
22 |
23 |
33 |
34 | ## Installing it
35 | sqlcommenter-java can installed in a couple of ways:
36 |
37 | ### From source
38 |
39 | Please visit [source page on Github](https://github.com/open-telemetry/opentelemetry-sqlcommenter/tree/main/java/sqlcommenter-java)
40 |
41 | ### Building it
42 |
43 | Next, after changing directories into `java/sqlcommenter-java`, run `./gradlew install`
44 | which should produce should output
45 | ```shell
46 | $ ./gradlew install
47 |
48 | BUILD SUCCESSFUL in 1s
49 | 7 actionable tasks: 1 executed, 6 up-to-date
50 | ```
51 |
52 | ### Verify installation
53 |
54 | sqlcommenter-java if properly installed should appear in the directory `$HOME/.m2/integrations/repository/io`.
55 |
56 | The following should be your directory structure:
57 | ```shell
58 | ~/.m2/repository/io
59 | └── com
60 | └── google
61 | └── cloud
62 | └── sqlcommenter
63 | ├── 0.0.1
64 | │ ├── sqlcommenter-java-0.0.1-javadoc.jar
65 | │ ├── sqlcommenter-java-0.0.1-javadoc.jar.asc
66 | │ ├── sqlcommenter-java-0.0.1-sources.jar
67 | │ ├── sqlcommenter-java-0.0.1-sources.jar.asc
68 | │ ├── sqlcommenter-java-0.0.1.jar
69 | │ ├── sqlcommenter-java-0.0.1.jar.asc
70 | │ └── sqlcommenter-java-0.0.1.pom
71 | └── maven-metadata-local.xml
72 | ```
73 |
74 | and then in your programs that use Maven, when building packages, please do
75 | ```shell
76 | mvn install -nsu
77 | ```
78 | to use look up local packages.
79 |
80 | ### Tests
81 |
82 | Tests can be run by
83 | ```shell
84 | $ ./gradlew test
85 | ```
--------------------------------------------------------------------------------
/docs/node-js/README.md:
--------------------------------------------------------------------------------
1 | # Node.js
2 |
3 | - [Node.js](#nodejs)
4 | - [Introduction](#introduction)
5 | - [Integrations](#integrations)
6 | - [Installing it](#installing-it)
7 | - [From source](#from-source)
8 | - [Verify Installation](#verify-installation)
9 |
10 | ## Introduction
11 |
12 | sqlcommenter is a suite of plugins/middleware/wrappers to augment SQL statements from ORMs/Querybuilders with comments that can be used later to correlate user code with SQL statements.
13 |
14 | ## Integrations
15 |
16 | sqlcommenter-nodejs provides support for the following:
17 |
18 | [](knex)
19 |
20 | [](express)
21 |
22 | [](sequelize)
23 |
24 |
25 |
36 |
37 | ## Installing it
38 | sqlcommenter-nodejs can installed in a couple of ways:
39 |
40 | ### From source
41 |
42 | The first step is to clone the repository. This can be done with [git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) by running:
43 | ```shell
44 | git clone https://github.com/open-telemetry/opentelemetry-sqlcommenter.git
45 | ```
46 | Inspect the source code and note the path to the package you want installed.
47 |
48 | ```shell
49 | sqlcommenter/nodejs/sqlcommenter-nodejs
50 | └── packages
51 | ├── knex
52 | │ ├── index.js
53 | │ ├── package.json
54 | │ ├── test
55 | │ └── ...
56 | └── sequelize
57 | ├── index.js
58 | ├── package.json
59 | ├── test
60 | └── ...
61 | ```
62 | Each folder in the `packages` directory can be installed by running
63 | ```shell
64 | npm install
65 | ```
66 | for example to install `@google-cloud/sqlcommenter-knex` in a given location, run `npm install /path/to/sqlcommenter-nodejs/packages/knex`. Same for every package(folder) in the `packages` directory.
67 | ```shell
68 | # install
69 | > npm install /path/to/sqlcommenter-nodejs/packages/knex
70 |
71 | + @google-cloud/sqlcommenter-knex@0.0.1
72 | ```
73 |
74 | ### Verify Installation
75 | If package is properly installed, running `npm list ` will output details of the package. Let's verify the installation of `@google-cloud/sqlcommenter-knex` below:
76 | ```shell
77 | # verify
78 | > npm list @google-cloud/sqlcommenter-knex
79 |
80 | project@0.0.0 path/to/project
81 | └── @google-cloud/sqlcommenter-knex@0.0.1 -> /path/to/sqlcommenter-nodejs/packages/knex
82 | ```
83 | Inspecting the `package.json` file after installation should also show the installed pacakge.
--------------------------------------------------------------------------------
/docs/node-js/express/README.md:
--------------------------------------------------------------------------------
1 | # Express js
2 |
3 | 
4 |
5 | - [Express js](#express-js)
6 | - [Introduction](#introduction)
7 | - [References](#references)
8 |
9 | ## Introduction
10 |
11 | We provide [express.js application-level middleware](https://expressjs.com/en/guide/using-middleware.html#middleware.application) with the following ORMs/Query-Builders:
12 |
13 | [](../knex)
14 |
15 | [](../sequelize)
16 |
17 |
18 |
30 |
31 |
32 | ## References
33 |
34 | Resource|URL
35 | ---|---
36 | express.js|
37 | express.js middleware|
--------------------------------------------------------------------------------
/docs/python/README.md:
--------------------------------------------------------------------------------
1 | # Python
2 | sqlcommenter support is available in Python for the following frameworks/ORMs:
3 |
4 | [](../python/django)
5 | [](../python/psycopg2)
6 | [](../python/SQLAlchemy)
7 | [](../python/flask)
8 |
--------------------------------------------------------------------------------
/docs/python/django/aws.md:
--------------------------------------------------------------------------------
1 | # Amazon Web Services
2 | 
3 |
4 | - [Amazon Web Services](#amazon-web-services)
5 | - [Introduction](#introduction)
6 | - [Requirements](#requirements)
7 | - [Addition to your code](#addition-to-your-code)
8 | - [References](#references)
9 |
10 |
11 | ## Introduction
12 |
13 | This guide will help you add [sqlcommenter](https://github.com/open-telemetry/opentelemetry-sqlcommenter) to your Django applications running on [Amazon Web Services (AWS)](https://aws.amazon.com)
14 |
15 | ## Requirements
16 |
17 | | Steps | Resource |
18 | | ------------------------- | -------------------------------------------------------------------------- |
19 | | Python on AWS | |
20 | | opentelemetry-sqlcommenter | |
21 | | Django 2.X | |
22 | | Python 3.X | |
23 |
24 | ## Addition to your code
25 |
26 | Firstly, please install [opentelemetry-sqlcommenter](README.md#installation).
27 |
28 | For any Django deployment, we can just edit your settings.py file and update the `MIDDLEWARE` section
29 | with
30 | ```python
31 | MIDDLEWARE = [
32 | 'opentelemetry.sqlcommenter.django.middleware.SqlCommenter',
33 | ...
34 | ]
35 | ```
36 |
37 | >If any middleware execute database queries (that you'd like commented by SqlCommenter), those middleware MUST appear after
38 | 'opentelemetry.sqlcommenter.django.middleware.SqlCommenter'
39 |
40 | ## References
41 |
42 | | Resource | URL |
43 | | ------------------------------------ | -------------------------------------------------------------------------- |
44 | | Deploying Python applications on AWS | |
45 | | General sqlcommenter Django guide | [link](README.md) |
--------------------------------------------------------------------------------
/docs/python/django/gcp.md:
--------------------------------------------------------------------------------
1 | # Google Cloud Platform
2 | 
3 |
4 | - [Google Cloud Platform](#google-cloud-platform)
5 | - [Introduction](#introduction)
6 | - [Requirements](#requirements)
7 | - [Addition to your code](#addition-to-your-code)
8 | - [References](#references)
9 |
10 |
11 | ## Introduction
12 |
13 | This guide will help you add [sqlcommenter](https://github.com/open-telemetry/opentelemetry-sqlcommenter) to your Django applications running on [Google Cloud Platform (GCP)](https://cloud.google.com)
14 |
15 | ## Requirements
16 |
17 | | Steps | Resource |
18 | | ------------------------- | ---------------------------------------------------- |
19 | | Django on GCP | |
20 | | opentelemetry-sqlcommenter | |
21 | | Django 2.X | |
22 | | Python 3.X | |
23 |
24 | ## Addition to your code
25 |
26 | Firstly, please install [opentelemetry-sqlcommenter](README.md#installation).
27 |
28 | For any Django deployment, we can just edit our settings.py file and update the `MIDDLEWARE` section as per:
29 |
30 | ```python
31 | MIDDLEWARE = [
32 | 'opentelemetry.sqlcommenter.django.middleware.SqlCommenter',
33 | ...
34 | ]
35 | ```
36 |
37 | >If any middleware execute database queries (that you'd like commented by SqlCommenter), those middleware MUST appear after
38 | 'opentelemetry.sqlcommenter.django.middleware.SqlCommenter'
39 |
40 | ## References
41 |
42 | | Resource | URL |
43 | | ---------------------------- | ------------------------------------------------ |
44 | | Running Django on GCP | |
45 | | Installing Django middleware | [link](README.md#installation) |
--------------------------------------------------------------------------------
/docs/python/django/local.md:
--------------------------------------------------------------------------------
1 | # Locally
2 | 
3 |
4 |
5 | - [Locally](#locally)
6 | - [Introduction](#introduction)
7 | - [Requirements](#requirements)
8 | - [Addition to your code](#addition-to-your-code)
9 | - [References](#references)
10 |
11 |
12 | ## Introduction
13 |
14 | This guide will help you add [sqlcommenter](https://github.com/open-telemetry/opentelemetry-sqlcommenter) to your Django applications running locally.
15 |
16 | Please see the reference for the fields added in the SQL comments [opentelemetry-sqlcommenter.Fields](README.md/#fields)
17 |
18 | ## Requirements
19 |
20 | | Steps | Resource |
21 | | ------------------------- | ---------------------------------------------------- |
22 | | Django | |
23 | | opentelemetry-sqlcommenter | |
24 | | Django 2.X | |
25 | | Python 3.X | |
26 |
27 | ## Addition to your code
28 |
29 | Firstly, please install [opentelemetry-sqlcommenter](README.md#installation).
30 |
31 | For any Django deployment, we can just edit our settings.py file and update the `MIDDLEWARE` section as per:
32 |
33 | ```python
34 | # settings.py
35 |
36 | MIDDLEWARE = [
37 | 'opentelemetry.sqlcommenter.django.middleware.SqlCommenter',
38 | ...
39 | ]
40 | ```
41 |
42 | >If any middleware execute database queries (that you'd like commented by SqlCommenter), those middleware MUST appear after
43 | 'opentelemetry.sqlcommenter.django.middleware.SqlCommenter'*
44 |
45 |
46 | ## References
47 |
48 | | Resource | URL |
49 | | ---------------------------- | ------------------------------------------------ |
50 | | Django quickstart | |
51 | | Installing Django middleware | [link](README.md/#installation) |
--------------------------------------------------------------------------------
/docs/ruby/README.md:
--------------------------------------------------------------------------------
1 | # Ruby
2 | 
3 |
4 | sqlcommenter support is available for the following [Ruby](https://www.ruby-lang.org/en/) ORMs/frameworks:
5 |
6 | [](ruby-on-rails)
7 |
8 |
16 |
--------------------------------------------------------------------------------
/java/sqlcommenter-java/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled class file
2 | *.class
3 |
4 | # Log file
5 | *.log
6 |
7 | # BlueJ files
8 | *.ctxt
9 |
10 | # Mobile Tools for Java (J2ME)
11 | .mtj.tmp/
12 |
13 | # Package Files #
14 | *.jar
15 | *.war
16 | *.nar
17 | *.ear
18 | *.zip
19 | *.tar.gz
20 | *.rar
21 |
22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23 | hs_err_pid*
24 |
25 | # Build files
26 | target/
27 |
28 | # Gradle
29 | build
30 | gradle.properties
31 | .gradle
32 | local.properties
33 | out/
34 |
35 | # IntelliJ IDEA
36 | .idea
37 | *.iml
38 | .editorconfig
39 |
40 | # Eclipse
41 | .classpath
42 | .project
43 | .settings
44 | bin
45 |
46 | # VS Code
47 | .vscode
--------------------------------------------------------------------------------
/java/sqlcommenter-java/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-bin.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/java/sqlcommenter-java/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/java/sqlcommenter-java/scripts/travis_script:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Travis build script, cf.
4 | # https://docs.travis-ci.com/user/customizing-the-build/#Implementing-Complex-Build-Steps.
5 |
6 | set -o errexit
7 | set -o xtrace
8 |
9 | case "$TRAVIS_OS_NAME" in
10 | "linux")
11 | source /opt/jdk_switcher/jdk_switcher.sh
12 | export JAVA8_HOME="$(jdk_switcher home oraclejdk8)"
13 | case "$TRAVIS_JDK_VERSION" in
14 | "oraclejdk9")
15 | ./gradlew clean assemble check --stacktrace
16 | ;;
17 | "oraclejdk8")
18 | export JAVA_HOMES="$(jdk_switcher home openjdk6)/jre:$(jdk_switcher home openjdk7)/jre:$(jdk_switcher home oraclejdk8)/jre:$(jdk_switcher home oraclejdk9)"
19 | ./gradlew clean assemble --stacktrace
20 | ./gradlew verGJF
21 | ;;
22 | *)
23 | echo "Unknown JDK version $TRAVIS_JDK_VERSION"
24 | exit 1
25 | ;;
26 | esac
27 | ;;
28 | "osx")
29 | # OS X is a separate case, because the JDK version is determined by the OS X image:
30 | # https://docs.travis-ci.com/user/reference/osx/#JDK-and-OS-X
31 | ./gradlew clean assemble --stacktrace
32 | ./gradlew check
33 | ;;
34 | *)
35 | echo "Unknown OS name $TRAVIS_OS_NAME"
36 | exit 1
37 | ;;
38 | esac
39 |
--------------------------------------------------------------------------------
/java/sqlcommenter-java/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = "opentelemetry-sqlcommenter"
2 |
--------------------------------------------------------------------------------
/java/sqlcommenter-java/src/main/java/io/opentelemetry/sqlcommenter/interceptors/SpringSQLCommenterInterceptor.java:
--------------------------------------------------------------------------------
1 | // Copyright The OpenTelemetry Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package io.opentelemetry.sqlcommenter.interceptors;
16 |
17 | import io.opentelemetry.sqlcommenter.threadlocalstorage.State;
18 | import javax.servlet.http.HttpServletRequest;
19 | import javax.servlet.http.HttpServletResponse;
20 | import org.springframework.web.method.HandlerMethod;
21 | import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
22 |
23 | public class SpringSQLCommenterInterceptor extends HandlerInterceptorAdapter {
24 |
25 | @Override
26 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
27 | throws Exception {
28 | // This method MUST always return true since we are
29 | // only grabbing information about the request.
30 |
31 | boolean isHandlerMethod = handler instanceof HandlerMethod;
32 | if (!isHandlerMethod) {
33 | // In this case, return promptly since we
34 | // can't extract details from the handler.
35 | return true;
36 | }
37 |
38 | HandlerMethod handlerMethod = (HandlerMethod) handler;
39 | String actionName = handlerMethod.getMethod().getName();
40 | String controllerName = handlerMethod.getBeanType().getSimpleName().replace("Controller", "");
41 |
42 | State.Holder.set(
43 | State.newBuilder()
44 | .withControllerName(controllerName)
45 | .withActionName(actionName)
46 | .withFramework("spring")
47 | .build());
48 |
49 | return true;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/java/sqlcommenter-java/src/main/java/io/opentelemetry/sqlcommenter/schibernate/SCHibernate.java:
--------------------------------------------------------------------------------
1 | // Copyright The OpenTelemetry Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package io.opentelemetry.sqlcommenter.schibernate;
16 |
17 | import io.opentelemetry.sqlcommenter.threadlocalstorage.SpanContextMetadata;
18 | import io.opentelemetry.sqlcommenter.threadlocalstorage.State;
19 | import org.hibernate.resource.jdbc.spi.StatementInspector;
20 |
21 | public class SCHibernate implements StatementInspector {
22 | private static final io.opencensus.trace.Tracer openCensusTracer =
23 | io.opencensus.trace.Tracing.getTracer();
24 |
25 | /**
26 | * inspect augments SQL with statements about the current code setup if any. It tries to check if
27 | * the current context contains OpenCensus information and if so, will augment the SQL but also it
28 | * will check if any web frameworks have inserted information about the currently running code
29 | * into thread local storage.
30 | */
31 | public String inspect(String sql) {
32 | State state = State.Holder.get();
33 |
34 | // Priority for OpenTelemetry commenting
35 | io.opentelemetry.api.trace.SpanContext spanContextOT =
36 | io.opentelemetry.api.trace.Span.current().getSpanContext();
37 |
38 | if (spanContextOT.isValid()) {
39 | if (spanContextOT.isSampled()) {
40 | state =
41 | State.newBuilder(state)
42 | .withSpanContextMetadata(
43 | SpanContextMetadata.fromOpenTelemetryContext(spanContextOT))
44 | .build();
45 | }
46 | } else {
47 | // Otherwise it is time to augment the SQL with information about the controller.
48 | io.opencensus.trace.SpanContext spanContext = openCensusTracer.getCurrentSpan().getContext();
49 | if (spanContext.isValid() && spanContext.getTraceOptions().isSampled()) {
50 | // Since our goal at this point is NOT to mutate the threadlocal storage's state.
51 | // yet we still need to carefully capture the Span information, we'll make
52 | // a copy of the thread local storage but set the TraceId and SpanId.
53 |
54 | // Finally replace this mvcState but it'll just be local to this function
55 | // and not the final ThreadLocalStorage State.
56 | state =
57 | State.newBuilder(state)
58 | .withSpanContextMetadata(SpanContextMetadata.fromOpenCensusContext(spanContext))
59 | .build();
60 | }
61 | }
62 |
63 | if (state == null) return sql;
64 |
65 | return state.formatAndAppendToSQL(sql);
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/java/sqlcommenter-java/src/test/java/io/opentelemetry/sqlcommenter/spring/backend/dao/PostRepository.java:
--------------------------------------------------------------------------------
1 | // Copyright The OpenTelemetry Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package io.opentelemetry.sqlcommenter.spring.backend.dao;
16 |
17 | import io.opentelemetry.sqlcommenter.spring.backend.domain.Post;
18 | import java.util.List;
19 | import org.springframework.data.repository.CrudRepository;
20 | import org.springframework.stereotype.Repository;
21 |
22 | @Repository
23 | public interface PostRepository extends CrudRepository {
24 |
25 | List findByTitle(String title);
26 | }
27 |
--------------------------------------------------------------------------------
/java/sqlcommenter-java/src/test/java/io/opentelemetry/sqlcommenter/spring/backend/dao/TagRepository.java:
--------------------------------------------------------------------------------
1 | // Copyright The OpenTelemetry Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package io.opentelemetry.sqlcommenter.spring.backend.dao;
16 |
17 | import io.opentelemetry.sqlcommenter.spring.backend.domain.Tag;
18 | import java.util.List;
19 | import org.springframework.data.repository.CrudRepository;
20 | import org.springframework.stereotype.Repository;
21 |
22 | @Repository
23 | public interface TagRepository extends CrudRepository {
24 |
25 | List findByNameIn(List names);
26 | }
27 |
--------------------------------------------------------------------------------
/java/sqlcommenter-java/src/test/java/io/opentelemetry/sqlcommenter/spring/backend/domain/Post.java:
--------------------------------------------------------------------------------
1 | // Copyright The OpenTelemetry Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package io.opentelemetry.sqlcommenter.spring.backend.domain;
16 |
17 | import java.util.ArrayList;
18 | import java.util.List;
19 | import javax.persistence.*;
20 |
21 | @Entity
22 | @Table(name = "post")
23 | public class Post {
24 |
25 | @Id @GeneratedValue private Long id;
26 |
27 | private String title;
28 |
29 | @ManyToMany
30 | @JoinTable(
31 | name = "post_tag",
32 | joinColumns = @JoinColumn(name = "post_id"),
33 | inverseJoinColumns = @JoinColumn(name = "tag_id"))
34 | private List tags = new ArrayList<>();
35 |
36 | public Long getId() {
37 | return id;
38 | }
39 |
40 | public void setId(Long id) {
41 | this.id = id;
42 | }
43 |
44 | public String getTitle() {
45 | return title;
46 | }
47 |
48 | public void setTitle(String title) {
49 | this.title = title;
50 | }
51 |
52 | public List getTags() {
53 | return tags;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/java/sqlcommenter-java/src/test/java/io/opentelemetry/sqlcommenter/spring/backend/domain/Tag.java:
--------------------------------------------------------------------------------
1 | // Copyright The OpenTelemetry Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package io.opentelemetry.sqlcommenter.spring.backend.domain;
16 |
17 | import javax.persistence.Entity;
18 | import javax.persistence.GeneratedValue;
19 | import javax.persistence.Id;
20 | import javax.persistence.Table;
21 |
22 | @Entity
23 | @Table(name = "tag")
24 | public class Tag {
25 |
26 | @Id @GeneratedValue private Long id;
27 |
28 | private String name;
29 |
30 | public Long getId() {
31 | return id;
32 | }
33 |
34 | public void setId(Long id) {
35 | this.id = id;
36 | }
37 |
38 | public String getName() {
39 | return name;
40 | }
41 |
42 | public void setName(String name) {
43 | this.name = name;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/java/sqlcommenter-java/src/test/java/io/opentelemetry/sqlcommenter/spring/backend/service/ForumService.java:
--------------------------------------------------------------------------------
1 | // Copyright The OpenTelemetry Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package io.opentelemetry.sqlcommenter.spring.backend.service;
16 |
17 | import io.opentelemetry.sqlcommenter.spring.backend.domain.Post;
18 | import java.util.List;
19 |
20 | public interface ForumService {
21 |
22 | Post newPost(String title, String... tags);
23 |
24 | List findAllByTitle(String title);
25 |
26 | Post findById(Long id);
27 | }
28 |
--------------------------------------------------------------------------------
/java/sqlcommenter-java/src/test/java/io/opentelemetry/sqlcommenter/spring/backend/service/ForumServiceImpl.java:
--------------------------------------------------------------------------------
1 | // Copyright The OpenTelemetry Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package io.opentelemetry.sqlcommenter.spring.backend.service;
16 |
17 | import io.opentelemetry.sqlcommenter.spring.backend.dao.PostRepository;
18 | import io.opentelemetry.sqlcommenter.spring.backend.dao.TagRepository;
19 | import io.opentelemetry.sqlcommenter.spring.backend.domain.Post;
20 | import java.util.Arrays;
21 | import java.util.List;
22 | import org.springframework.beans.factory.annotation.Autowired;
23 | import org.springframework.stereotype.Service;
24 | import org.springframework.transaction.annotation.Transactional;
25 |
26 | @Service
27 | public class ForumServiceImpl implements ForumService {
28 |
29 | @Autowired private PostRepository postRepository;
30 |
31 | @Autowired private TagRepository tagRepository;
32 |
33 | @Override
34 | @Transactional
35 | public Post newPost(String title, String... tags) {
36 | Post post = new Post();
37 | post.setTitle(title);
38 | post.getTags().addAll(tagRepository.findByNameIn(Arrays.asList(tags)));
39 | return postRepository.save(post);
40 | }
41 |
42 | @Override
43 | @Transactional(readOnly = true)
44 | public List findAllByTitle(String title) {
45 | return postRepository.findByTitle(title);
46 | }
47 |
48 | @Override
49 | @Transactional
50 | public Post findById(Long id) {
51 | return postRepository.findById(id).orElse(null);
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/java/sqlcommenter-java/src/test/java/io/opentelemetry/sqlcommenter/util/SCHibernateWrapper.java:
--------------------------------------------------------------------------------
1 | // Copyright The OpenTelemetry Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package io.opentelemetry.sqlcommenter.util;
16 |
17 | import io.opentelemetry.sqlcommenter.schibernate.SCHibernate;
18 | import java.util.ArrayList;
19 | import java.util.List;
20 |
21 | /**
22 | * The {@link SCHibernateWrapper} class wraps the {@link
23 | * SCHibernate} class so that we can also get a chance to
24 | * intercept the executed statements and assert them during testing.
25 | */
26 | public class SCHibernateWrapper extends SCHibernate {
27 |
28 | private static List beforeSqlStatements = new ArrayList<>();
29 |
30 | private static List afterSqlStatements = new ArrayList<>();
31 |
32 | public static List getBeforeSqlStatements() {
33 | return beforeSqlStatements;
34 | }
35 |
36 | public static List getAfterSqlStatements() {
37 | return afterSqlStatements;
38 | }
39 |
40 | public static void reset() {
41 | beforeSqlStatements.clear();
42 | afterSqlStatements.clear();
43 | }
44 |
45 | @Override
46 | public String inspect(String beforeSql) {
47 | beforeSqlStatements.add(beforeSql);
48 | String afterSql = super.inspect(beforeSql);
49 | afterSqlStatements.add(afterSql);
50 | return afterSql;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/java/sqlcommenter-java/src/test/resources/META-INF/jdbc-hsqldb.properties:
--------------------------------------------------------------------------------
1 | hibernate.dialect=org.hibernate.dialect.HSQLDialect
2 | jdbc.driverClassName=org.hsqldb.jdbc.JDBCDriver
3 | jdbc.dataSourceClassName=org.hsqldb.jdbc.JDBCDataSource
4 | jdbc.url=jdbc:hsqldb:mem:test
5 | jdbc.username=sa
6 | jdbc.password=
--------------------------------------------------------------------------------
/java/sqlcommenter-java/src/test/resources/logback-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | DEBUG
5 |
6 | target/test.log
7 | false
8 |
9 | %-5p [%t]: %c{1} - %m%n
10 | UTF-8
11 |
12 |
13 |
14 |
15 | TRACE
16 |
17 |
18 | %-5p [%t]:%X{txId} %c{1} - %m%n
19 | UTF-8
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/nodejs/sqlcommenter-nodejs/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 |
8 | # Runtime data
9 | pids
10 | *.pid
11 | *.seed
12 | *.pid.lock
13 |
14 | # Directory for instrumented libs generated by jscoverage/JSCover
15 | lib-cov
16 |
17 | # Coverage directory used by tools like istanbul
18 | coverage
19 |
20 | # nyc test coverage
21 | .nyc_output
22 |
23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24 | .grunt
25 |
26 | # Bower dependency directory (https://bower.io/)
27 | bower_components
28 |
29 | # node-waf configuration
30 | .lock-wscript
31 |
32 | # Compiled binary addons (https://nodejs.org/api/addons.html)
33 | build/Release
34 |
35 | # Dependency directories
36 | node_modules/
37 | jspm_packages/
38 |
39 | # TypeScript v1 declaration files
40 | typings/
41 |
42 | # Optional npm cache directory
43 | .npm
44 |
45 | # Optional eslint cache
46 | .eslintcache
47 |
48 | # Optional REPL history
49 | .node_repl_history
50 |
51 | # Output of 'npm pack'
52 | *.tgz
53 |
54 | # Yarn Integrity file
55 | .yarn-integrity
56 |
57 | # dotenv environment variables file
58 | .env
59 |
60 | # next.js build output
61 | .next
62 |
--------------------------------------------------------------------------------
/nodejs/sqlcommenter-nodejs/README.md:
--------------------------------------------------------------------------------
1 | # sqlcommenter
2 |
3 | sqlcommenter is a suite of plugins/middleware/wrappers to augment SQL statements from ORMs/Querybuilders
4 | with comments that can be used later to correlate user code with SQL statements.
5 |
6 | It supports Node v6 and above to use ES6 features.
7 |
8 | ### Supported frameworks:
9 |
10 | - Sequelize
11 | - Knex.js
12 |
13 | ### Installation
14 |
15 | Go into either of the packages [packages/knex](./packages/knex) or [packages/sequelize](./packages/sequelize)
16 | and then you can run respectively
17 |
18 | Middleware|Command|URL
19 | ---|---|---
20 | Knex.js|`npm install @google-cloud/sqlcommenter-knex`|https://www.npmjs.com/package/@google-cloud/sqlcommenter-knex
21 | Sequelize.js|`npm install @google-cloud/sqlcommenter-sequelize`|https://www.npmjs.com/package/@google-cloud/sqlcommenter-sequelize
22 |
--------------------------------------------------------------------------------
/nodejs/sqlcommenter-nodejs/packages/sqlcommenter-knex/README.md:
--------------------------------------------------------------------------------
1 | # sqlcommenter-knex
2 |
3 | sqlcommenter is a plugin/middleware/wrapper to augment SQL statements from Knex.js
4 | with comments that can be used later to correlate user code with SQL statements.
5 |
6 | It supports Node v6 and above to use ES6 features.
7 |
8 | ### Installation
9 | ```shell
10 | npm install @opentelemetry/sqlcommenter-knex
11 | ```
12 |
13 | ### Usage
14 | ```javascript
15 | const sknex = require('@opentelemetry/sqlcommenter-knex');
16 | ```
17 |
--------------------------------------------------------------------------------
/nodejs/sqlcommenter-nodejs/packages/sqlcommenter-knex/hooks.js:
--------------------------------------------------------------------------------
1 | // Copyright The OpenTelemetry Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | const hooks = require('async_hooks')
16 | const store = new Map();
17 |
18 | const hook = hooks.createHook({
19 | init: (asyncId, _, triggerAsyncId) => {
20 | if (store.has(triggerAsyncId)) {
21 | store.set(asyncId, store.get(triggerAsyncId))
22 | }
23 | },
24 | destroy: (asyncId) => {
25 | if (store.has(asyncId)) {
26 | store.delete(asyncId)
27 | }
28 | }
29 | });
30 |
31 | hook.enable();
32 |
33 | const createContext = (data) => {
34 | store.set(hooks.executionAsyncId(), data);
35 | return data;
36 | };
37 |
38 | const getContext = () => {
39 | return store.get(hooks.executionAsyncId());
40 | };
41 |
42 | module.exports = { createContext, getContext };
43 |
--------------------------------------------------------------------------------
/nodejs/sqlcommenter-nodejs/packages/sqlcommenter-knex/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@opentelemetry/sqlcommenter-knex",
3 | "version": "0.1.0",
4 | "description": "Middleware and wrappers to correlate SQL statements from Knex.js and Express.js",
5 | "main": "index.js",
6 | "directories": {
7 | "test": "test"
8 | },
9 | "devDependencies": {
10 | "@opencensus/nodejs": "^0.0.22",
11 | "@opencensus/propagation-tracecontext": "^0.0.22",
12 | "@opentelemetry/api": "^1.0.3",
13 | "@opentelemetry/core": "^0.24.0",
14 | "@opentelemetry/node": "^0.24.0",
15 | "chai": "^4.2.0",
16 | "chai-http": "^4.3.0",
17 | "express": "^4.17.0",
18 | "knex": "^0.19.5",
19 | "mocha": "^8.2.0",
20 | "rewiremock": "^3.14.3",
21 | "sequelize": "^6.3.3",
22 | "sinon": "^9.0.3",
23 | "sinon-chai": "^3.5.0"
24 | },
25 | "peerDependencies": {
26 | "@opencensus/nodejs": "^0.0.22",
27 | "@opencensus/propagation-tracecontext": "^0.0.22",
28 | "@opentelemetry/core": "^0.24.0"
29 | },
30 | "engines": {
31 | "node": ">=6.0.0"
32 | },
33 | "scripts": {
34 | "test": "mocha --recursive"
35 | },
36 | "repository": {
37 | "type": "git",
38 | "url": "open-telemetry/opentelemetry-sqlcommenter"
39 | },
40 | "author": "OpenTelemetry Authors",
41 | "license": "Apache-2.0",
42 | "publishConfig": {
43 | "access": "public"
44 | },
45 | "homepage": "https://open-telemetry.github.io/opentelemetry-sqlcommenter/node-js/knex/"
46 | }
47 |
--------------------------------------------------------------------------------
/nodejs/sqlcommenter-nodejs/packages/sqlcommenter-knex/provider/index.js:
--------------------------------------------------------------------------------
1 | // Copyright The OpenTelemetry Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | const OpenCensus = require('./opencensus');
16 | const OpenTelemetry = require('./opentelemetry');
17 |
18 | const providers = {
19 | 'opentelemetry': OpenTelemetry,
20 | 'opencensus': OpenCensus,
21 | }
22 |
23 | exports.attachComments = function attachComments(providerName, comments) {
24 | // Verify we have a comments object to modify
25 | if (!comments || typeof comments !== 'object') return;
26 |
27 | // Lookup the provider by name, or use the default.
28 | let provider = providers[String(providerName).toLowerCase()] || OpenCensus;
29 | provider.addW3CTraceContext(comments);
30 | }
31 |
--------------------------------------------------------------------------------
/nodejs/sqlcommenter-nodejs/packages/sqlcommenter-knex/provider/opencensus.js:
--------------------------------------------------------------------------------
1 | // Copyright The OpenTelemetry Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | const {tracer} = require('@opencensus/nodejs');
16 | const {toW3CTraceContext} = require('../util');
17 |
18 | exports.addW3CTraceContext = function(comments) {
19 | if (tracer.active) {
20 | toW3CTraceContext(tracer.currentRootSpan, comments);
21 | }
22 | };
23 |
--------------------------------------------------------------------------------
/nodejs/sqlcommenter-nodejs/packages/sqlcommenter-knex/provider/opentelemetry.js:
--------------------------------------------------------------------------------
1 | // Copyright The OpenTelemetry Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | const {context, defaultTextMapSetter} = require('@opentelemetry/api');
16 | const {HttpTraceContextPropagator} = require('@opentelemetry/core')
17 |
18 | exports.addW3CTraceContext = function(comments) {
19 | let propagator = new HttpTraceContextPropagator();
20 | propagator.inject(context.active(), comments, defaultTextMapSetter);
21 | };
22 |
--------------------------------------------------------------------------------
/nodejs/sqlcommenter-nodejs/packages/sqlcommenter-knex/test/rewiremock.js:
--------------------------------------------------------------------------------
1 | // Copyright The OpenTelemetry Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // This module enables pre-configuring rewiremock for all test cases, rather than repeatedly configuring in each test
16 |
17 | const rewiremock = require('rewiremock/node');
18 | // nothng more than `plugins.node`, but it might change how filename resolution works
19 |
20 | rewiremock.overrideEntryPoint(module);
21 | module.exports = rewiremock;
22 |
--------------------------------------------------------------------------------
/nodejs/sqlcommenter-nodejs/packages/sqlcommenter-sequelize/README.md:
--------------------------------------------------------------------------------
1 | # sqlcommenter-sequelize
2 |
3 | sqlcommenter is a plugin/middleware/wrapper to augment SQL statements from Sequelize.js
4 | with comments that can be used later to correlate user code with SQL statements.
5 |
6 | It supports Node v6 and above to use ES6 features.
7 |
8 | ### Installation
9 | ```shell
10 | npm install @opentelemetry/sqlcommenter-sequelize
11 | ```
12 |
13 | ### Usage
14 | ```javascript
15 | const ssequelize = require('@opentelemetry/sqlcommenter-sequelize');
16 | ```
17 |
--------------------------------------------------------------------------------
/nodejs/sqlcommenter-nodejs/packages/sqlcommenter-sequelize/hooks.js:
--------------------------------------------------------------------------------
1 | // Copyright The OpenTelemetry Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | const hooks = require('async_hooks')
16 | const store = new Map();
17 |
18 | const hook = hooks.createHook({
19 | init: (asyncId, _, triggerAsyncId) => {
20 | if (store.has(triggerAsyncId)) {
21 | store.set(asyncId, store.get(triggerAsyncId))
22 | }
23 | },
24 | destroy: (asyncId) => {
25 | if (store.has(asyncId)) {
26 | store.delete(asyncId)
27 | }
28 | }
29 | });
30 |
31 | hook.enable();
32 |
33 | const createContext = (data) => {
34 | store.set(hooks.executionAsyncId(), data);
35 | return data;
36 | };
37 |
38 | const getContext = () => {
39 | return store.get(hooks.executionAsyncId());
40 | };
41 |
42 | module.exports = { createContext, getContext };
43 |
--------------------------------------------------------------------------------
/nodejs/sqlcommenter-nodejs/packages/sqlcommenter-sequelize/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@opentelemetry/sqlcommenter-sequelize",
3 | "version": "0.1.0",
4 | "description": "Middleware and wrappers to correlate SQL statements from Sequelize.js and Express.js",
5 | "main": "index.js",
6 | "directories": {
7 | "test": "test"
8 | },
9 | "devDependencies": {
10 | "@opencensus/nodejs": "^0.0.22",
11 | "@opencensus/propagation-tracecontext": "^0.0.22",
12 | "@opentelemetry/api": "^1.0.3",
13 | "@opentelemetry/core": "^0.24.0",
14 | "@opentelemetry/node": "^0.24.0",
15 | "chai": "^4.2.0",
16 | "chai-http": "^4.3.0",
17 | "express": "^4.17.0",
18 | "mocha": "^6.1.4",
19 | "rewiremock": "^3.14.3",
20 | "sequelize": "^6.3.3",
21 | "sinon": "^9.0.3",
22 | "sinon-chai": "^3.5.0"
23 | },
24 | "peerDependencies": {
25 | "@opencensus/nodejs": "^0.0.22",
26 | "@opencensus/propagation-tracecontext": "^0.0.22",
27 | "@opentelemetry/core": "^0.24.0"
28 | },
29 | "engines": {
30 | "node": ">=6.0.0"
31 | },
32 | "scripts": {
33 | "test": "mocha --recursive"
34 | },
35 | "repository": {
36 | "type": "git",
37 | "url": "open-telemetry/opentelemetry-sqlcommenter"
38 | },
39 | "author": "OpenTelemetry Authors",
40 | "license": "Apache-2.0",
41 | "publishConfig": {
42 | "access": "public"
43 | },
44 | "homepage": "https://open-telemetry.github.io/opentelemetry-sqlcommenter/node-js/sequelize/"
45 | }
46 |
47 |
--------------------------------------------------------------------------------
/nodejs/sqlcommenter-nodejs/packages/sqlcommenter-sequelize/provider/index.js:
--------------------------------------------------------------------------------
1 | // Copyright The OpenTelemetry Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | const OpenCensus = require('./opencensus');
16 | const OpenTelemetry = require('./opentelemetry');
17 |
18 | const providers = {
19 | 'opentelemetry': OpenTelemetry,
20 | 'opencensus': OpenCensus,
21 | }
22 |
23 | exports.attachComments = function attachComments(providerName, comments) {
24 | // Verify we have a comments object to modify
25 | if (!comments || typeof comments !== 'object') return;
26 |
27 | // Lookup the provider by name, or use the default.
28 | let provider = providers[String(providerName).toLowerCase()] || OpenCensus;
29 | provider.addW3CTraceContext(comments);
30 | }
31 |
--------------------------------------------------------------------------------
/nodejs/sqlcommenter-nodejs/packages/sqlcommenter-sequelize/provider/opencensus.js:
--------------------------------------------------------------------------------
1 | // Copyright The OpenTelemetry Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | const {tracer} = require('@opencensus/nodejs');
16 | const {toW3CTraceContext} = require('../util');
17 |
18 | exports.addW3CTraceContext = function(comments) {
19 | if (tracer.active) {
20 | toW3CTraceContext(tracer.currentRootSpan, comments);
21 | }
22 | };
23 |
--------------------------------------------------------------------------------
/nodejs/sqlcommenter-nodejs/packages/sqlcommenter-sequelize/provider/opentelemetry.js:
--------------------------------------------------------------------------------
1 | // Copyright The OpenTelemetry Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | const {context, defaultTextMapSetter} = require('@opentelemetry/api');
16 | const {HttpTraceContextPropagator} = require('@opentelemetry/core')
17 |
18 | exports.addW3CTraceContext = function(comments) {
19 | let propagator = new HttpTraceContextPropagator();
20 | propagator.inject(context.active(), comments, defaultTextMapSetter);
21 | };
22 |
--------------------------------------------------------------------------------
/nodejs/sqlcommenter-nodejs/packages/sqlcommenter-sequelize/test/rewiremock.js:
--------------------------------------------------------------------------------
1 | // Copyright The OpenTelemetry Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // This module enables pre-configuring rewiremock for all test cases, rather than repeatedly configuring in each test
16 |
17 | const rewiremock = require('rewiremock/node');
18 | // nothng more than `plugins.node`, but it might change how filename resolution works
19 |
20 | rewiremock.overrideEntryPoint(module);
21 | module.exports = rewiremock;
--------------------------------------------------------------------------------
/nodejs/sqlcommenter-nodejs/samples/express-opentelemetry/knexConnection.js:
--------------------------------------------------------------------------------
1 | // Copyright The OpenTelemetry Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | const { wrapMainKnexAsMiddleware } = require("@google-cloud/sqlcommenter-knex");
16 | const Knex = require("knex");
17 |
18 | const sqlcommenterMiddleware = wrapMainKnexAsMiddleware(
19 | Knex,
20 | {
21 | traceparent: true,
22 | tracestate: true,
23 |
24 | // These are optional and will cause a high cardinality burst traced queries
25 | db_driver: false,
26 | route: false,
27 | },
28 | { TraceProvider: "OpenTelemetry" }
29 | );
30 |
31 | const knex = Knex({
32 | client: "pg",
33 | connection: {
34 | host: process.env.DBHOST,
35 | user: process.env.DBUSERNAME,
36 | password: process.env.DBPASSWORD,
37 | database: "postgres",
38 | },
39 | });
40 |
41 | module.exports = {
42 | knex,
43 | sqlcommenterMiddleware,
44 | };
45 |
--------------------------------------------------------------------------------
/nodejs/sqlcommenter-nodejs/samples/express-opentelemetry/knexServer.js:
--------------------------------------------------------------------------------
1 | // Copyright The OpenTelemetry Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | const { LogLevel } = require("@opentelemetry/core");
16 | const { NodeTracerProvider } = require("@opentelemetry/node");
17 | const { BatchSpanProcessor } = require("@opentelemetry/tracing");
18 | const {
19 | TraceExporter,
20 | } = require("@google-cloud/opentelemetry-cloud-trace-exporter");
21 | const { logger, sleep } = require("./util");
22 |
23 | const tracerProvider = new NodeTracerProvider({
24 | logLevel: LogLevel.DEBUG,
25 | logger,
26 | });
27 | tracerProvider.addSpanProcessor(
28 | new BatchSpanProcessor(new TraceExporter({ logger }), {
29 | bufferSize: 500,
30 | bufferTimeout: 5 * 1000,
31 | })
32 | );
33 | tracerProvider.register();
34 |
35 | // OpenTelemetry initialization should happen before importing any libraries
36 | // that it instruments
37 | const express = require("express");
38 | const app = express();
39 | const { sqlcommenterMiddleware, knex } = require("./knexConnection");
40 |
41 | const tracer = tracerProvider.getTracer(__filename);
42 |
43 | async function main() {
44 | if (!(await knex.schema.hasTable("Todos"))) {
45 | console.error("Todos table does not exist. Run `npm run createTodos`");
46 | process.exit(1);
47 | }
48 |
49 | const PORT = 8000;
50 |
51 | // SQLCommenter express middleware injects the route into the traces
52 | app.use(sqlcommenterMiddleware);
53 |
54 | app.get("/", async (req, res) => {
55 | const span = tracer.startSpan("sleep for no reason (parent)");
56 | await sleep(250);
57 | span.end();
58 |
59 | const getRecordsSpan = tracer.startSpan("query records with knex");
60 | await tracer.withSpan(getRecordsSpan, async () => {
61 | tracer.startSpan("testing 123").end();
62 | const todos = await knex.select().table("Todos").limit(20);
63 | const countByDone = await knex
64 | .select("done", knex.raw("COUNT(id) as count"))
65 | .table("Todos")
66 | .groupBy("done");
67 | res.json({ countByDone, todos });
68 | });
69 | getRecordsSpan.end();
70 | });
71 | app.listen(PORT, async () => {
72 | console.log(`⚡️[server]: Server is running at https://localhost:${PORT}`);
73 | });
74 | }
75 |
76 | main().catch(console.error);
77 |
--------------------------------------------------------------------------------
/nodejs/sqlcommenter-nodejs/samples/express-opentelemetry/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "express-opentelemetry",
3 | "version": "1.0.0",
4 | "private": true,
5 | "description": "A sample app express.js app demonstrating SQLCommenter OpenTelemetry integration",
6 | "main": "index.js",
7 | "scripts": {
8 | "preinstall": "for package_dir in ../../packages/sqlcommenter-*; do pushd $package_dir; npm pack; popd; done",
9 | "createTodos": "node -e \"const {createSomeTodos} = require('./sequelizeModels');createSomeTodos().then(console.log).catch(console.error)\"",
10 | "sequelizeServer": "node sequelizeServer.js",
11 | "knexServer": "DEBUG=knex:query node knexServer.js"
12 | },
13 | "author": "",
14 | "license": "ISC",
15 | "dependencies": {
16 | "@google-cloud/opentelemetry-cloud-trace-exporter": "^0.7.0",
17 | "@google-cloud/sqlcommenter-knex": "file:../../packages/sqlcommenter-knex/google-cloud-sqlcommenter-knex-0.0.3.tgz",
18 | "@google-cloud/sqlcommenter-sequelize": "file:../../packages/sqlcommenter-sequelize/google-cloud-sqlcommenter-sequelize-0.0.3.tgz",
19 | "@opencensus/nodejs": "0.0.22",
20 | "@opencensus/propagation-tracecontext": "0.0.22",
21 | "@opentelemetry/core": "^0.12.0",
22 | "@opentelemetry/node": "^0.12.0",
23 | "@opentelemetry/plugin-express": "^0.11.0",
24 | "@opentelemetry/plugin-http": "^0.12.0",
25 | "@opentelemetry/plugin-pg": "^0.11.0",
26 | "@opentelemetry/plugin-pg-pool": "^0.11.0",
27 | "@opentelemetry/tracing": "^0.12.0",
28 | "express": "^4.17.1",
29 | "knex": "^0.21.12",
30 | "pg": "^8.4.2",
31 | "pg-hstore": "^2.3.3",
32 | "sequelize": "^6.3.5"
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/nodejs/sqlcommenter-nodejs/samples/express-opentelemetry/sequelizeModels.js:
--------------------------------------------------------------------------------
1 | // Copyright The OpenTelemetry Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | const { Sequelize, DataTypes } = require("sequelize");
16 | const {
17 | wrapSequelizeAsMiddleware,
18 | } = require("@google-cloud/sqlcommenter-sequelize");
19 |
20 | const sequelize = new Sequelize(
21 | "postgres",
22 | process.env.DBUSERNAME,
23 | process.env.DBPASSWORD,
24 | {
25 | host: process.env.DBHOST,
26 | dialect: process.env.DBDIALECT || "postgres",
27 | }
28 | );
29 | const sqlcommenterMiddleware = wrapSequelizeAsMiddleware(
30 | sequelize,
31 | {
32 | traceparent: true,
33 | tracestate: true,
34 |
35 | // These are optional and will cause a high cardinality burst traced queries
36 | client_timezone: false,
37 | db_driver: false,
38 | route: false,
39 | },
40 | { TraceProvider: "OpenTelemetry" }
41 | );
42 |
43 | const Todo = sequelize.define(
44 | "Todo",
45 | {
46 | // Model attributes are defined here
47 | title: {
48 | type: DataTypes.STRING,
49 | allowNull: false,
50 | },
51 | description: {
52 | type: DataTypes.STRING,
53 | },
54 | done: {
55 | type: DataTypes.BOOLEAN,
56 | defaultValue: false,
57 | },
58 | },
59 | {}
60 | );
61 |
62 | async function createSomeTodos() {
63 | await sequelize.sync();
64 |
65 | const boringTasks = [];
66 | for (let i = 0; i < 1000; ++i) {
67 | boringTasks.push({
68 | title: `Boring task ${i}`,
69 | description: "A mundane task",
70 | done: true,
71 | });
72 | }
73 |
74 | await Todo.bulkCreate([
75 | { title: "Do dishes" },
76 | { title: "Buy groceries" },
77 | {
78 | title: "Do laundry",
79 | description: "Finish before Thursday!",
80 | },
81 | { title: "Clean room" },
82 | { title: "Wash car" },
83 | ...boringTasks,
84 | ]);
85 | }
86 |
87 | module.exports = {
88 | createSomeTodos,
89 | sequelize,
90 | sqlcommenterMiddleware,
91 | Todo,
92 | };
93 |
--------------------------------------------------------------------------------
/nodejs/sqlcommenter-nodejs/samples/express-opentelemetry/sequelizeServer.js:
--------------------------------------------------------------------------------
1 | // Copyright The OpenTelemetry Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | const { NodeTracerProvider } = require("@opentelemetry/node");
16 | const { BatchSpanProcessor } = require("@opentelemetry/tracing");
17 | const {
18 | TraceExporter,
19 | } = require("@google-cloud/opentelemetry-cloud-trace-exporter");
20 | const { logger, sleep } = require("./util");
21 |
22 | const tracerProvider = new NodeTracerProvider();
23 | tracerProvider.addSpanProcessor(
24 | new BatchSpanProcessor(new TraceExporter({ logger }), {
25 | bufferSize: 500,
26 | bufferTimeout: 5 * 1000,
27 | })
28 | );
29 | tracerProvider.register();
30 |
31 | // OpenTelemetry initialization should happen before importing any libraries
32 | // that it instruments
33 | const express = require("express");
34 | const app = express();
35 | const {
36 | Todo,
37 | sequelize,
38 | sqlcommenterMiddleware,
39 | } = require("./sequelizeModels");
40 |
41 | const tracer = tracerProvider.getTracer(__filename);
42 |
43 | async function main() {
44 | await sequelize.sync();
45 |
46 | const PORT = 8000;
47 |
48 | // SQLCommenter express middleware injects the route into the traces
49 | app.use(sqlcommenterMiddleware);
50 |
51 | app.get("/", async (req, res) => {
52 | const span = tracer.startSpan("sleep for no reason (parent)");
53 | await sleep(250);
54 | span.end();
55 |
56 | const getRecordsSpan = tracer.startSpan("query records with sequelize");
57 | await tracer.withSpan(getRecordsSpan, async () => {
58 | const todos = await Todo.findAll({ limit: 20 });
59 | const countByDone = await Todo.findAll({
60 | attributes: [
61 | "done",
62 | [sequelize.fn("COUNT", sequelize.col("id")), "count"],
63 | ],
64 | group: "done",
65 | });
66 | res.json({ countByDone, todos });
67 | });
68 | getRecordsSpan.end();
69 | });
70 | app.listen(PORT, async () => {
71 | console.log(`⚡️[server]: Server is running at https://localhost:${PORT}`);
72 | });
73 | }
74 |
75 | main().catch(console.error);
76 |
--------------------------------------------------------------------------------
/nodejs/sqlcommenter-nodejs/samples/express-opentelemetry/util.js:
--------------------------------------------------------------------------------
1 | // Copyright The OpenTelemetry Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | module.exports = {
16 | sleep(time) {
17 | return new Promise((resolve) => setTimeout(resolve, time));
18 | },
19 |
20 | logger: {
21 | warn: console.log,
22 | info: console.log,
23 | error: console.log,
24 | debug: console.log,
25 | },
26 | };
27 |
--------------------------------------------------------------------------------
/package_it.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash -eu
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | #!/bin/bash
18 |
19 | final_zip=sqlcommenter-mono.zip
20 | original_branch=$(git rev-parse --abbrev-ref HEAD)
21 | gen_branch=expand-$(date | tr " " "_" | tr ":" "_")
22 | git checkout -b $gen_branch || (echo "Failed to checkout $gen_branch" && exit)
23 |
24 | rm -rf $final_zip && zip -r $final_zip $(ls) || (git checkout $original_branch && git branch -D $gen_branch && exit)
25 | git checkout $original_branch && git branch -D $gen_branch
26 |
--------------------------------------------------------------------------------
/python/samples/.gitignore:
--------------------------------------------------------------------------------
1 | venv/
2 |
--------------------------------------------------------------------------------
/python/samples/README.md:
--------------------------------------------------------------------------------
1 | ## Postgres sample with OpenTelemetry
2 | To run the sample:
3 | ```bash
4 | # Create virtualenv and install dependencies
5 | python3 -m venv venv
6 | source venv/bin/activate
7 | pip install -r requirements.txt
8 |
9 | # Run with Postgres DSN environment variable
10 | export POSTGRES_DSN="postgresql://:@?host="
11 | python psycopgy_opentelemetry_sample.py
12 | ```
13 |
--------------------------------------------------------------------------------
/python/samples/requirements.txt:
--------------------------------------------------------------------------------
1 | ../sqlcommenter-python[opentelemetry]
2 | opentelemetry-api==1.4.1
3 | opentelemetry-exporter-gcp-trace==1.0.0
4 | opentelemetry-instrumentation-psycopg2==0.23b2
5 | opentelemetry-sdk==1.4.1
6 | psycopg2==2.8.6
7 | psycopg2-binary==2.8.6
8 |
--------------------------------------------------------------------------------
/python/sqlcommenter-python/.gitignore:
--------------------------------------------------------------------------------
1 | *.egg-info
2 | *.py[co]
3 | build/
4 | *.sw[op]
5 | .tox/
6 | MANIFEST
7 | venv/
8 |
--------------------------------------------------------------------------------
/python/sqlcommenter-python/opentelemetry/__init__.py:
--------------------------------------------------------------------------------
1 | # See the License for the specific language governing permissions and
2 | # limitations under the License.
3 |
4 | __import__('pkg_resources').declare_namespace(__name__)
5 |
--------------------------------------------------------------------------------
/python/sqlcommenter-python/opentelemetry/sqlcommenter/__init__.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | import sys
18 |
19 | if sys.version_info.major <= 2:
20 | import urllib
21 | url_quote_fn = urllib.quote
22 | else:
23 | import urllib.parse
24 | url_quote_fn = urllib.parse.quote
25 |
26 | KEY_VALUE_DELIMITER = ','
27 |
28 |
29 | def generate_sql_comment(**meta):
30 | """
31 | Return a SQL comment with comma delimited key=value pairs created from
32 | **meta kwargs.
33 | """
34 | if not meta: # No entries added.
35 | return ''
36 |
37 | # Sort the keywords to ensure that caching works and that testing is
38 | # deterministic. It eases visual inspection as well.
39 | return ' /*' + KEY_VALUE_DELIMITER.join(
40 | '{}={!r}'.format(url_quote(key), url_quote(value)) for key, value in sorted(meta.items())
41 | if value is not None
42 | ) + '*/'
43 |
44 |
45 | def url_quote(s):
46 | if not isinstance(s, (str, bytes)):
47 | return s
48 | quoted = url_quote_fn(s)
49 | # Since SQL uses '%' as a keyword, '%' is a by-product of url quoting
50 | # e.g. foo,bar --> foo%2Cbar
51 | # thus in our quoting, we need to escape it too to finally give
52 | # foo,bar --> foo%%2Cbar
53 | return quoted.replace('%', '%%')
54 |
--------------------------------------------------------------------------------
/python/sqlcommenter-python/opentelemetry/sqlcommenter/django/__init__.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
--------------------------------------------------------------------------------
/python/sqlcommenter-python/opentelemetry/sqlcommenter/flask.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | from __future__ import absolute_import
18 |
19 | try:
20 | import flask
21 | from flask import request
22 | except ImportError:
23 | flask = None
24 |
25 |
26 | def get_flask_info():
27 | """
28 | Get available info from the current flask request, if we're in a
29 | flask request-response cycle. Else, return an empty dict.
30 | """
31 | info = {}
32 | # https://flask.palletsprojects.com/en/1.1.x/api/#flask.has_request_context
33 | if flask and request:
34 | info['framework'] = 'flask:%s' % flask.__version__
35 | if request.endpoint:
36 | info['controller'] = request.endpoint
37 | if request.url_rule and request.url_rule.rule:
38 | info['route'] = request.url_rule.rule
39 | return info
40 |
--------------------------------------------------------------------------------
/python/sqlcommenter-python/opentelemetry/sqlcommenter/opencensus.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | from __future__ import absolute_import
18 |
19 | try:
20 | from opencensus.trace import execution_context
21 | from opencensus.trace.propagation import trace_context_http_header_format
22 | except ImportError:
23 | execution_context = None
24 |
25 |
26 | def get_opencensus_values():
27 | """
28 | Return the OpenCensus Trace and Span IDs if Span ID is set in the
29 | OpenCensus execution context.
30 | """
31 | if execution_context:
32 | span_ctx = execution_context.get_opencensus_tracer().span_context
33 | span_id = span_ctx.span_id
34 | if span_id:
35 | # Insert the W3C TraceContext generated
36 | w3C_trace_ctx = trace_context_http_header_format.TraceContextPropagator()
37 | return w3C_trace_ctx.to_headers(span_ctx)
38 | else:
39 | raise ImportError('opencensus is not installed.')
40 | return {}
41 |
--------------------------------------------------------------------------------
/python/sqlcommenter-python/opentelemetry/sqlcommenter/opentelemetry.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | from __future__ import absolute_import
18 |
19 | try:
20 | from opentelemetry.trace.propagation.tracecontext import (
21 | TraceContextTextMapPropagator,
22 | )
23 |
24 | propagator = TraceContextTextMapPropagator()
25 | except ImportError:
26 | propagator = None
27 |
28 |
29 | def get_opentelemetry_values():
30 | """
31 | Return the OpenTelemetry Trace and Span IDs if Span ID is set in the
32 | OpenTelemetry execution context.
33 | """
34 | if propagator:
35 | # Insert the W3C TraceContext generated
36 | headers = {}
37 | propagator.inject(headers)
38 | return headers
39 | else:
40 | raise ImportError("OpenTelemetry is not installed.")
41 |
--------------------------------------------------------------------------------
/python/sqlcommenter-python/opentelemetry/sqlcommenter/psycopg2/__init__.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
--------------------------------------------------------------------------------
/python/sqlcommenter-python/opentelemetry/sqlcommenter/sqlalchemy/__init__.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
--------------------------------------------------------------------------------
/python/sqlcommenter-python/opentelemetry/sqlcommenter/version.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 |
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | __version__ = "0.1.0"
18 |
--------------------------------------------------------------------------------
/python/sqlcommenter-python/runtests.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | import os
18 | import sys
19 | import unittest
20 |
21 | # Django, Flask, psycopg2, and sqlalchemy are only installed in their
22 | # respective testing environments. See tox.ini for details.
23 |
24 | try:
25 | import django
26 | from django.test.runner import DiscoverRunner
27 | except ImportError:
28 | django = None
29 |
30 | try:
31 | import flask
32 | import pytest
33 | except ImportError:
34 | flask = None
35 |
36 | try:
37 | import psycopg2
38 | except ImportError:
39 | psycopg2 = None
40 |
41 | try:
42 | import sqlalchemy
43 | except ImportError:
44 | sqlalchemy = None
45 |
46 |
47 | def run_unittests(module):
48 | testsuite = unittest.TestLoader().discover(module)
49 | result = unittest.TextTestRunner(verbosity=1).run(testsuite)
50 | sys.exit(any(result.failures or result.errors))
51 |
52 |
53 | def run_django_tests():
54 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tests.django.settings')
55 | django.setup()
56 | runner = DiscoverRunner()
57 | failures = runner.run_tests(['tests.django'])
58 | sys.exit(failures)
59 |
60 |
61 | def run_flask_tests():
62 | failures = pytest.main(['tests/flask/tests.py'])
63 | sys.exit(failures)
64 |
65 |
66 | def main():
67 | if django:
68 | run_django_tests()
69 | elif flask:
70 | run_flask_tests()
71 | elif psycopg2:
72 | run_unittests('tests.psycopg2')
73 | elif sqlalchemy:
74 | run_unittests('tests.sqlalchemy')
75 | else:
76 | run_unittests('tests.generic')
77 |
78 |
79 | if __name__ == '__main__':
80 | main()
81 |
--------------------------------------------------------------------------------
/python/sqlcommenter-python/setup.cfg:
--------------------------------------------------------------------------------
1 | [flake8]
2 | exclude = build,.git,.tox
3 | max-line-length = 119
4 |
5 | [isort]
6 | combine_as_imports = true
7 | default_section = THIRDPARTY
8 | include_trailing_comma = true
9 | known_first_party = sqlcommenter
10 | line_length = 79
11 | multi_line_output = 5
12 |
13 | [metadata]
14 | name=opentelemetry_sqlcommenter
15 | version=attr: opentelemetry.sqlcommenter.version.__version__
16 | author=OpenTelemetry Authors
17 | author_email=cncf-opentelemetry-contributors@lists.cncf.io
18 | description=(Augment SQL statements with meta information about frameworks and the running environment.)
19 | long_description = file: README.md
20 | long_description_content_type=text/markdown
21 | license=BSD
22 | classifiers=
23 | Development Status :: 4 - Beta
24 | Environment :: Web Environment
25 | Intended Audience :: Developers
26 | License :: OSI Approved :: BSD License
27 | Operating System :: OS Independent
28 | Programming Language :: Python :: 3
29 | Programming Language :: Python :: 3.6
30 | Programming Language :: Python :: 3.7
31 | Programming Language :: Python :: 3.8
32 | Programming Language :: Python :: 3.9
33 | Topic :: Utilities
34 | Framework :: Django
35 | Framework :: Django :: 2.1
36 | Framework :: Django :: 2.2
37 |
38 | [options]
39 | python_requires = >=3
40 | packages = find:
41 |
42 | [options.extras_require]
43 | django=django>=1.11
44 | psycopg2=psycopg2
45 | sqlalchemy=sqlalchemy
46 | opencensus=opencensus
47 | opentelemetry=opentelemetry-api~=1.0
48 |
49 |
--------------------------------------------------------------------------------
/python/sqlcommenter-python/setup.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | from setuptools import setup
18 |
19 | setup()
20 |
--------------------------------------------------------------------------------
/python/sqlcommenter-python/tests/__init__.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
--------------------------------------------------------------------------------
/python/sqlcommenter-python/tests/compat.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | """Python 2 compatibility shims."""
18 |
19 | import sys
20 | import unittest
21 |
22 | try:
23 | from unittest import mock
24 | except ImportError: # Python 2
25 | import mock
26 |
27 |
28 | def skipIfPy2(testcase):
29 | return unittest.skipIf(
30 | sys.version_info.major == 2, "Feature only support in python3+"
31 | )(testcase)
32 |
33 |
34 | __all__ = ["mock"]
35 |
--------------------------------------------------------------------------------
/python/sqlcommenter-python/tests/django/__init__.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
--------------------------------------------------------------------------------
/python/sqlcommenter-python/tests/django/app_urls.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | from django.urls import path
18 |
19 | from . import views
20 |
21 | app_name = 'app_urls'
22 |
23 | urlpatterns = [
24 | path('app-path/', views.home, name='app-path'),
25 | ]
26 |
--------------------------------------------------------------------------------
/python/sqlcommenter-python/tests/django/models.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | from django.db import models
18 |
19 |
20 | class Author(models.Model):
21 | name = models.CharField(max_length=255)
22 |
23 | def __str__(self):
24 | return self.name
25 |
--------------------------------------------------------------------------------
/python/sqlcommenter-python/tests/django/settings.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | DATABASES = {
18 | 'default': {
19 | 'ENGINE': 'django.db.backends.sqlite3',
20 | },
21 | }
22 |
23 | INSTALLED_APPS = ['tests.django']
24 |
25 | ROOT_URLCONF = 'tests.django.urls'
26 |
27 | SECRET_KEY = 'commenter_tests_secret_key'
28 |
--------------------------------------------------------------------------------
/python/sqlcommenter-python/tests/django/urls.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | from django.urls import include, path
18 |
19 | from . import views
20 |
21 | urlpatterns = [
22 | path('', views.home, name='home'),
23 | path('path/', views.home, name='some-path'),
24 | path('app-urls/', include('tests.django.app_urls')),
25 | ]
26 |
--------------------------------------------------------------------------------
/python/sqlcommenter-python/tests/django/views.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | from django.http import HttpResponse
18 |
19 | from .models import Author
20 |
21 |
22 | def home(request):
23 | list(Author.objects.all())
24 | return HttpResponse()
25 |
--------------------------------------------------------------------------------
/python/sqlcommenter-python/tests/flask/__init__.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
--------------------------------------------------------------------------------
/python/sqlcommenter-python/tests/flask/app.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | from flask import Flask
18 | from opentelemetry.sqlcommenter.flask import get_flask_info
19 |
20 | app = Flask(__name__)
21 |
22 |
23 | @app.route('/flask-info')
24 | def flask_info():
25 | return get_flask_info()
26 |
27 |
28 | @app.errorhandler(404)
29 | def handle_bad_request(e):
30 | return get_flask_info(), 404
31 |
--------------------------------------------------------------------------------
/python/sqlcommenter-python/tests/flask/tests.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | import json
18 |
19 | import flask
20 | import pytest
21 | from opentelemetry.sqlcommenter.flask import get_flask_info
22 |
23 | from .app import app
24 |
25 | # Following the example provided at
26 | # https://flask.palletsprojects.com/en/1.1.x/testing/#the-testing-skeleton
27 |
28 |
29 | @pytest.fixture
30 | def client():
31 | app.config['TESTING'] = True
32 | with app.test_client() as client:
33 | yield client
34 |
35 |
36 | def test_get_flask_info_in_request_context(client):
37 | expected = {
38 | 'controller': 'flask_info',
39 | 'framework': 'flask:%s' % flask.__version__,
40 | 'route': '/flask-info',
41 | }
42 | resp = client.get('/flask-info')
43 | assert json.loads(resp.data.decode('utf-8')) == expected
44 |
45 |
46 | def test_get_flask_info_in_404_error_context(client):
47 | expected = {
48 | 'framework': 'flask:%s' % flask.__version__,
49 | }
50 | resp = client.get('/doesnt-exist')
51 | assert json.loads(resp.data.decode('utf-8')) == expected
52 |
53 |
54 | def test_get_flask_info_outside_request_context(client):
55 | assert get_flask_info() == {}
56 |
--------------------------------------------------------------------------------
/python/sqlcommenter-python/tests/generic/__init__.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
--------------------------------------------------------------------------------
/python/sqlcommenter-python/tests/generic/test_generate_sql_comment.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | from unittest import TestCase
18 |
19 | from opentelemetry.sqlcommenter import generate_sql_comment
20 |
21 |
22 | class GenerateSqlCommentTests(TestCase):
23 | def test_no_args(self):
24 | self.assertEqual(generate_sql_comment(), '')
25 |
26 | def test_end_comment_escaping(self):
27 | self.assertIn("a='%%2A/abc'", generate_sql_comment(a='*/abc'))
28 |
29 | def test_bytes(self):
30 | self.assertIn("a='%%2A/abc'", generate_sql_comment(a=b'*/abc'))
31 |
32 | def test_url_quoting(self):
33 | self.assertIn("foo='bar%%2Cbaz'", generate_sql_comment(foo='bar,baz'))
34 |
--------------------------------------------------------------------------------
/python/sqlcommenter-python/tests/generic/test_opencensus.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | from unittest import TestCase
18 |
19 | import six
20 | from opentelemetry.sqlcommenter.opencensus import get_opencensus_values
21 |
22 | from ..compat import mock
23 | from ..opencensus_mock import mock_opencensus_tracer
24 |
25 |
26 | class OpenCensusTests(TestCase):
27 | def test_not_installed(self):
28 | with mock.patch('opentelemetry.sqlcommenter.opencensus.execution_context', new=None):
29 | with six.assertRaisesRegex(self, ImportError, 'opencensus is not installed'):
30 | get_opencensus_values()
31 |
32 | def test_no_values(self):
33 | self.assertEqual(get_opencensus_values(), {})
34 |
35 | def test_values(self):
36 | with mock_opencensus_tracer():
37 | self.assertEqual(get_opencensus_values(), {
38 | 'traceparent': '00-trace id-span id-00',
39 | 'tracestate': 'congo=t61rcWkgMzE,rojo=00f067aa0ba902b7',
40 | })
41 |
--------------------------------------------------------------------------------
/python/sqlcommenter-python/tests/generic/test_opentelemetry.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | from unittest import TestCase
18 |
19 | import six
20 | from opentelemetry.sqlcommenter.opentelemetry import get_opentelemetry_values
21 |
22 | from ..compat import mock, skipIfPy2
23 | from ..opentelemetry_mock import mock_opentelemetry_context
24 |
25 |
26 | @skipIfPy2
27 | class OpenTelemetryTests(TestCase):
28 | def test_not_installed(self):
29 | with mock.patch("opentelemetry.sqlcommenter.opentelemetry.propagator", new=None):
30 | with six.assertRaisesRegex(
31 | self, ImportError, "OpenTelemetry is not installed"
32 | ):
33 | get_opentelemetry_values()
34 |
35 | def test_no_values(self):
36 | self.assertEqual(get_opentelemetry_values(), {})
37 |
38 | def test_trace_parent_and_tracestate(self):
39 | with mock_opentelemetry_context():
40 | self.assertEqual(
41 | get_opentelemetry_values(),
42 | {
43 | "traceparent": "00-000000000000000000000000deadbeef-000000000000beef-00",
44 | "tracestate": "some_key=some_value",
45 | },
46 | )
47 |
48 | def test_trace_flags(self):
49 | from opentelemetry import trace
50 | with mock_opentelemetry_context(trace_flags=trace.TraceFlags.SAMPLED):
51 | self.assertEqual(
52 | get_opentelemetry_values(),
53 | {
54 | "traceparent": "00-000000000000000000000000deadbeef-000000000000beef-01",
55 | "tracestate": "some_key=some_value",
56 | },
57 | )
58 |
59 | def test_empty_trace_state(self):
60 | with mock_opentelemetry_context(trace_state={}):
61 | self.assertEqual(
62 | get_opentelemetry_values(),
63 | {
64 | "traceparent": "00-000000000000000000000000deadbeef-000000000000beef-00",
65 | },
66 | )
67 |
--------------------------------------------------------------------------------
/python/sqlcommenter-python/tests/opencensus_mock.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | from collections import OrderedDict
18 | from contextlib import contextmanager
19 |
20 | from .compat import mock
21 |
22 |
23 | def get_opencensus_tracer_mock():
24 | class Tracer:
25 | @property
26 | def span_context(self):
27 | class Context:
28 | @property
29 | def span_id(self):
30 | return 'span id'
31 |
32 | @property
33 | def trace_id(self):
34 | return 'trace id'
35 |
36 | @property
37 | def trace_options(self):
38 | return TraceOptions()
39 |
40 | @property
41 | def tracestate(self):
42 | od = OrderedDict()
43 | od['congo'] = 't61rcWkgMzE'
44 | od['rojo'] = '00f067aa0ba902b7'
45 | return od
46 |
47 | return Context()
48 | return Tracer()
49 |
50 |
51 | class TraceOptions():
52 | def __init__(self, enabled=False):
53 | self.enabled = enabled
54 |
55 |
56 | @contextmanager
57 | def mock_opencensus_tracer():
58 | path = 'opencensus.trace.execution_context.get_opencensus_tracer'
59 | with mock.patch(path, get_opencensus_tracer_mock):
60 | yield
61 |
--------------------------------------------------------------------------------
/python/sqlcommenter-python/tests/opentelemetry_mock.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | from contextlib import contextmanager
18 |
19 | try:
20 | from opentelemetry import context, trace
21 |
22 | @contextmanager
23 | def mock_opentelemetry_context(
24 | trace_id=0xDEADBEEF, span_id=0xBEEF, trace_flags=None, trace_state=None
25 | ):
26 | if trace_state is None:
27 | trace_state = [("some_key", "some_value")]
28 |
29 | span_context = trace.SpanContext(
30 | trace_id=trace_id,
31 | span_id=span_id,
32 | is_remote=True,
33 | trace_flags=trace_flags,
34 | trace_state=trace.TraceState(trace_state),
35 | )
36 | ctx = trace.set_span_in_context(trace.span.NonRecordingSpan(span_context))
37 | token = context.attach(ctx)
38 | try:
39 | yield
40 | finally:
41 | context.detach(token)
42 |
43 |
44 | except ImportError:
45 | # python2.7 tests will not have opentelemetry installed
46 | @contextmanager
47 | def mock_opentelemetry_context(*args, **kwargs):
48 | yield
49 |
--------------------------------------------------------------------------------
/python/sqlcommenter-python/tests/psycopg2/__init__.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
--------------------------------------------------------------------------------
/python/sqlcommenter-python/tests/sqlalchemy/__init__.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
--------------------------------------------------------------------------------
/python/sqlcommenter-python/tests/tests.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | from unittest import TestCase
18 |
19 | from opentelemetry.sqlcommenter import generate_sql_comment
20 |
21 | from .opencensus_mock import mock_opencensus_tracer
22 |
23 |
24 | class GenerateSqlCommentTests(TestCase):
25 | def test_no_args(self):
26 | # As per internal issue #28, we've commented out
27 | # the old defaults such as os.uname() information.
28 | self.assertEqual(generate_sql_comment(), '')
29 |
30 | def test_end_comment_escaping(self):
31 | self.assertIn(r'%%2A/abc', generate_sql_comment(a='*/abc'))
32 |
33 | def test_url_quoting(self):
34 | self.assertIn("foo='bar%%2Cbaz'", generate_sql_comment(foo='bar,baz'))
35 |
36 | def test_opencensus_not_available(self):
37 | self.assertEqual(generate_sql_comment(with_opencensus=True), '')
38 | self.assertEqual(generate_sql_comment(with_opencensus=False), '')
39 |
40 | def test_opencensus_disabled(self):
41 | with mock_opencensus_tracer():
42 | self.assertEqual(generate_sql_comment(with_opencensus=False), '')
43 |
44 | def test_opencensus_enabled(self):
45 | with mock_opencensus_tracer():
46 | self.assertEqual(
47 | generate_sql_comment(with_opencensus=True),
48 | " /*traceparent='00-trace%%20id-span%%20id-00',"
49 | "tracestate='congo%%3Dt61rcWkgMzE%%2Crojo%%3D00f067aa0ba902b7'*/"
50 | )
51 |
--------------------------------------------------------------------------------
/python/sqlcommenter-python/tox.ini:
--------------------------------------------------------------------------------
1 | [tox]
2 | envlist =
3 | py3{6,7,8,9}-django{21,22,30,31,32}
4 | py3{6,7,8,9}-psycopg2
5 | py3{6,7,8,9}-{flask,generic,sqlalchemy}
6 | flake8
7 |
8 | #
9 | [testenv]
10 | setenv =
11 | PYTHONDONTWRITEBYTECODE = 1
12 | PYTHONWARNINGS = all
13 | deps =
14 | django21: Django>=2.1,<2.2
15 | django22: Django>=2.2,<3.0
16 | django30: Django>=3.0,<3.1
17 | django31: Django>=3.1,<3.2
18 | django32: Django>=3.2,<3.3
19 | flask: flask
20 | flask: pytest
21 | opencensus
22 | opentelemetry-api~=1.0
23 | psycopg2: forbiddenfruit
24 | psycopg2: psycopg2-binary
25 | sqlalchemy: sqlalchemy
26 | six
27 | commands =
28 | python runtests.py
29 |
30 | [testenv:flake8]
31 | skip_install = True
32 | deps =
33 | flake8
34 | isort < 5
35 | commands =
36 | flake8
37 | isort --recursive --check-only --diff
38 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/.gitignore:
--------------------------------------------------------------------------------
1 | *.gem
2 | *.rbc
3 | /.config
4 | /coverage/
5 | /InstalledFiles
6 | /pkg/
7 | /spec/reports/
8 | /spec/examples.txt
9 | /test/tmp/
10 | /test/version_tmp/
11 | /tmp/
12 |
13 | # Used by dotenv library to load environment variables.
14 | # .env
15 |
16 | ## Specific to RubyMotion:
17 | .dat*
18 | .repl_history
19 | build/
20 | *.bridgesupport
21 | build-iPhoneOS/
22 | build-iPhoneSimulator/
23 |
24 | ## Specific to RubyMotion (use of CocoaPods):
25 | #
26 | # We recommend against adding the Pods directory to your .gitignore. However
27 | # you should judge for yourself, the pros and cons are mentioned at:
28 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29 | #
30 | # vendor/Pods/
31 |
32 | ## Documentation cache and generated files:
33 | /.yardoc/
34 | /_yardoc/
35 | /doc/
36 | /rdoc/
37 |
38 | ## Environment normalization:
39 | /.bundle/
40 | /vendor/bundle
41 | /lib/bundler/man/
42 |
43 | # for a library or gem, you might want to ignore these files since the code is
44 | # intended to run in multiple environments; otherwise, check them in:
45 | # Gemfile.lock
46 | # .ruby-version
47 | # .ruby-gemset
48 |
49 | # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50 | .rvmrc
51 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/README.md:
--------------------------------------------------------------------------------
1 | # sqlcommenter-ruby
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/marginalia-opencensus/.gitignore:
--------------------------------------------------------------------------------
1 | /.bundle/
2 | /.yardoc
3 | /_yardoc/
4 | /coverage/
5 | /doc/
6 | /pkg/
7 | /spec/reports/
8 | /tmp/
9 |
10 | # rspec failure tracking
11 | .rspec_status
12 | Gemfile.lock
13 | /vendor/
14 | /spec/gemfiles/*.gemfile.lock
15 | /spec/gemfiles/.bundle/
16 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/marginalia-opencensus/.rspec:
--------------------------------------------------------------------------------
1 | --format documentation
2 | --color
3 | --require spec_helper
4 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/marginalia-opencensus/.rubocop.yml:
--------------------------------------------------------------------------------
1 | require:
2 | - rubocop-performance
3 | - rubocop-rspec
4 |
5 | AllCops:
6 | TargetRubyVersion: 2.3
7 | Exclude:
8 | - 'spec/dummy/db/**/*'
9 | - 'vendor/**/*'
10 |
11 | Bundler/OrderedGems:
12 | Enabled: false
13 |
14 | Capybara/FeatureMethods:
15 | EnabledMethods:
16 | - feature
17 |
18 | Layout/MultilineMethodCallIndentation:
19 | EnforcedStyle: indented
20 |
21 | Lint/AmbiguousBlockAssociation:
22 | Enabled: false
23 |
24 | Metrics/AbcSize:
25 | Enabled: false
26 |
27 | Metrics/BlockLength:
28 | Exclude:
29 | - Rakefile
30 | - spec/**/*_spec.rb
31 | - spec/dummy/config/environments/*.rb
32 | - spec/factories.rb
33 |
34 | Metrics/ClassLength:
35 | Max: 125
36 |
37 | Metrics/LineLength:
38 | Max: 120
39 |
40 | Metrics/MethodLength:
41 | Max: 25
42 |
43 | Metrics/ModuleLength:
44 | Exclude:
45 | - spec/**/*_spec.rb
46 |
47 | Metrics/PerceivedComplexity:
48 | Enabled: false
49 |
50 | Naming/MemoizedInstanceVariableName:
51 | Enabled: false
52 |
53 | Naming/FileName:
54 | Exclude:
55 | - lib/marginalia-opencensus.rb
56 |
57 | Naming/PredicateName:
58 | Exclude:
59 | - spec/**/*.rb
60 |
61 | Naming/VariableNumber:
62 | EnforcedStyle: snake_case
63 |
64 | Naming/UncommunicativeMethodParamName:
65 | Enabled: false
66 |
67 | Rails/ApplicationRecord:
68 | Enabled: false
69 |
70 | Rails/CreateTableWithTimestamps:
71 | Enabled: false
72 |
73 | Rails/SkipsModelValidations:
74 | Enabled: false
75 |
76 | RSpec/FilePath:
77 | CustomTransform:
78 | OpenCensus: opencensus
79 |
80 | Style/CollectionMethods:
81 | Enabled: true
82 |
83 | Style/Documentation:
84 | Enabled: false
85 |
86 | Style/Lambda:
87 | EnforcedStyle: literal
88 |
89 | Style/StderrPuts:
90 | Enabled: false
91 |
92 | Style/SignalException:
93 | EnforcedStyle: semantic
94 |
95 | Style/TrailingCommaInArguments:
96 | Enabled: false
97 |
98 | Style/TrailingCommaInArrayLiteral:
99 | Enabled: false
100 |
101 | Style/TrailingCommaInHashLiteral:
102 | Enabled: false
103 |
104 | Rails:
105 | Enabled: true
106 |
107 | Rails/Date:
108 | EnforcedStyle: strict
109 |
110 | Rails/FindBy:
111 | Enabled: true
112 | Include:
113 | - app/commands/**/*.rb
114 | - app/models/**/*.rb
115 | - app/view_models/**/*.rb
116 |
117 | RSpec/BeforeAfterAll:
118 | Enabled: false
119 |
120 | RSpec/ContextWording:
121 | Enabled: false
122 |
123 | RSpec/DescribeClass:
124 | Exclude:
125 | - spec/views/**/*.rb
126 |
127 | RSpec/ExampleLength:
128 | Enabled: false
129 |
130 | RSpec/ExpectInHook:
131 | Enabled: false
132 |
133 | RSpec/InstanceVariable:
134 | Enabled: false
135 |
136 | RSpec/LetSetup:
137 | Enabled: false
138 |
139 | RSpec/MessageSpies:
140 | Enabled: false
141 |
142 | RSpec/MultipleExpectations:
143 | Enabled: false
144 |
145 | RSpec/NestedGroups:
146 | Enabled: false
147 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/marginalia-opencensus/.travis.yml:
--------------------------------------------------------------------------------
1 | ---
2 | sudo: false
3 | language: ruby
4 | cache: bundler
5 | bundler_args: --path ../../vendor/bundle --without debug
6 | env:
7 | global:
8 | - TRAVIS=1
9 | before_install: gem install bundler -v 2.0.1
10 | script: bundle exec rspec
11 | matrix:
12 | include:
13 | - name: Rubocop
14 | gemfile: spec/gemfiles/rubocop.gemfile
15 | rvm: 2.6.3
16 | script: bundle exec rubocop
17 | - gemfile: spec/gemfiles/rails_5_2.gemfile
18 | rvm: 2.3.8
19 | - gemfile: spec/gemfiles/rails_6_0.gemfile
20 | rvm: 2.5.5
21 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/marginalia-opencensus/Gemfile:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | source 'https://rubygems.org'
4 |
5 | gem 'rails', '~> 6.0.0.rc1'
6 | # https://github.com/rails/rails/blob/v6.0.0.rc1/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb#L12
7 | gem 'sqlite3', '~> 1.3', '>= 1.3.6'
8 |
9 | gemspec
10 |
11 | group :debug do
12 | gem 'byebug'
13 | end
14 |
15 | eval_gemfile File.expand_path('rubocop.gemfile', __dir__)
16 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/marginalia-opencensus/README.md:
--------------------------------------------------------------------------------
1 | # marginalia-opencensus
2 |
3 | Adds [OpenCensus] support to [Marginalia].
4 |
5 | [Marginalia]: https://github.com/basecamp/marginalia/
6 | [OpenCensus]: https://opencensus.io/
7 |
8 | ## Installation
9 |
10 | Add this line to your application's Gemfile:
11 |
12 | ```ruby
13 | gem 'marginalia-opencensus'
14 | ```
15 |
16 | And then execute:
17 |
18 | $ bundle
19 |
20 | Or install it yourself as:
21 |
22 | $ gem install marginalia-opencensus
23 |
24 | ## Usage
25 |
26 | This gem registers an `opencensus` component and appends it to the list of default Marginalia components.
27 |
28 | In the default configuration, OpenCensus trace will be automatically added to the end of Marginalia comments.
29 |
30 | By the default the trace contains OpenCensus Span names from the current one to root, joined with `~`.
31 |
32 | See `Marginalia::OpenCensus` documentation for more configuration options.
33 |
34 | ## Development
35 |
36 | After checking out the repo, run `bin/setup` to install dependencies.
37 | Then, run `bundle exec rake` to run the tests (more on testing below).
38 |
39 | You can also run `bin/console` for an interactive prompt that will allow you to experiment.
40 |
41 | To install this gem onto your local machine, run `bundle exec rake install`.
42 | To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`,
43 | which will create a git tag for the version, push git commits and tags,
44 | and push the `.gem` file to [rubygems.org](https://rubygems.org).
45 |
46 | ## Testing
47 |
48 | marginalia-opencensus is tested with multiple Rails versions.
49 |
50 | We use the following gems for testing marginalia-opencensus:
51 |
52 | 1. [RSpec](https://github.com/rspec/rspec) + [RSpec Rails](https://github.com/rspec/rspec-rails) as the testing framework.
53 | 2. [combustion](https://github.com/pat/combustion) for integration tests with a Rails application.
54 | 3. [wwtd](https://github.com/grosser/wwtd) for emulating Travis CI locally.
55 |
56 | To run the test suite with the latest release of Rails, run:
57 |
58 | ```bash
59 | bundle exec rake
60 | ```
61 |
62 | To run the entire test suite (all supported Rails version, rubocop, etc), run:
63 |
64 | ```bash
65 | bundle exec wwtd
66 | ```
67 |
68 | To start a web server with the embedded test application, run:
69 |
70 | ```bash
71 | bin/rails s
72 | ```
73 |
74 | ## Contributing
75 |
76 | Bug reports and pull requests are welcome on GitHub at **TODO: REPO URL**.
77 |
78 | This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the
79 | [Contributor Covenant](http://contributor-covenant.org) code of conduct.
80 |
81 | ## License
82 |
83 | TODO: license.
84 |
85 | ## Code of Conduct
86 |
87 | TODO: code of conduct.
88 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/marginalia-opencensus/Rakefile:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require 'bundler/gem_tasks'
4 | require 'rspec/core/rake_task'
5 |
6 | APP_RAKEFILE = File.expand_path('spec/internal/Rakefile', __dir__)
7 | load 'rails/tasks/engine.rake'
8 |
9 | RSpec::Core::RakeTask.new(:spec)
10 |
11 | task default: :spec
12 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/marginalia-opencensus/bin/console:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | # frozen_string_literal: true
3 |
4 | require 'bundler/setup'
5 | require 'marginalia/opencensus'
6 |
7 | # You can add fixtures and/or initialization code here to make experimenting
8 | # with your gem easier. You can also use a different console, if you like.
9 |
10 | # (If you use this, don't forget to add pry to your Gemfile!)
11 | # require "pry"
12 | # Pry.start
13 |
14 | require 'irb'
15 | IRB.start(__FILE__)
16 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/marginalia-opencensus/bin/rails:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | # frozen_string_literal: true
3 |
4 | APP_PATH = File.expand_path('../spec/internal/config/application', __dir__)
5 | require File.expand_path('../spec/internal/config/boot', __dir__)
6 | require 'rails/commands'
7 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/marginalia-opencensus/bin/setup:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | set -euo pipefail
3 | IFS=$'\n\t'
4 | set -vx
5 |
6 | bundle install
7 |
8 | # Do any other automated setup that you need to do here
9 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/marginalia-opencensus/lib/marginalia-opencensus.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | # frozen_string_literal: true
18 |
19 | require_relative 'marginalia/opencensus'
20 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/marginalia-opencensus/lib/marginalia/opencensus.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | # frozen_string_literal: true
18 |
19 | require 'marginalia'
20 | require 'opencensus'
21 |
22 | require_relative 'opencensus/marginalia_components'
23 | require_relative 'opencensus/version'
24 |
25 | module Marginalia
26 | module OpenCensus
27 | class << self
28 | # @return [String] The string to join span names with.
29 | attr_accessor :join_span_names_with
30 |
31 | # Decides which items to include in the `span_names` component.
32 | # @return A callable that accepts a single {::OpenCensus::Trace::SpanContext} and returns a {Boolean}.
33 | # The span is included in the output only if this callable returns `true`.
34 | attr_accessor :span_names_filter
35 |
36 | # Formats an individual span name.
37 | # @return A callable that accepts a single {::OpenCensus::Trace::SpanContext} and returns a {String}.
38 | attr_accessor :span_name_formatter
39 | end
40 |
41 | self.join_span_names_with = '~'
42 | self.span_names_filter = ->(_span_context) { true }
43 | self.span_name_formatter = ->(span_context) { span_context.this_span.name }
44 |
45 | # Enumerates all span contexts from the given one until the root one.
46 | # The root context itself is not included.
47 | #
48 | # @param [::OpenCensus::Trace::SpanContext] span_context
49 | # @return [Enumerable<::OpenCensus::Trace::SpanContext>]
50 | def self.path_to_root(span_context)
51 | return to_enum(:path_to_root, span_context) unless block_given?
52 |
53 | cur = span_context
54 | while (parent = cur.parent)
55 | yield cur
56 | cur = parent
57 | end
58 | end
59 | end
60 | end
61 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/marginalia-opencensus/lib/marginalia/opencensus/marginalia_components.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | # frozen_string_literal: true
18 |
19 | module Marginalia
20 | module Comment
21 | # @return [String, nil]
22 | def self.traceparent
23 | return unless (span_context = ::OpenCensus::Trace.span_context)
24 |
25 | # Following W3C Tracecontext.traceparent as per:
26 | # https://www.w3.org/TR/trace-context/#traceparent-field
27 | format(
28 | '00-%s-%s-%.2d',
29 | trace_id: span_context.trace_id,
30 | span_id: span_context.span_id,
31 | trace_options: span_context.trace_options,
32 | )
33 | end
34 |
35 | # @return [String, nil]
36 | def self.tracestate
37 | # Tracestate is not yet supported in OpenCensus-Ruby.
38 | # See issue https://github.com/census-instrumentation/opencensus-ruby/issues/88
39 | # However, when added, please follow:
40 | # https://www.w3.org/TR/trace-context/#tracestate-field
41 | nil
42 | end
43 | end
44 | end
45 |
46 | Marginalia::Comment.components += %i[traceparent tracestate]
47 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/marginalia-opencensus/lib/marginalia/opencensus/version.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | # frozen_string_literal: true
18 |
19 | module Marginalia
20 | module OpenCensus
21 | VERSION = '0.1.0'
22 | end
23 | end
24 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/marginalia-opencensus/marginalia-opencensus.gemspec:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | lib = File.expand_path('lib', __dir__)
4 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5 | require 'marginalia/opencensus/version'
6 |
7 | Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
8 | spec.name = 'marginalia-opencensus'
9 | spec.version = Marginalia::OpenCensus::VERSION
10 | spec.authors = ['Google developers']
11 | spec.email = ['sqlcommenter@googlegroups.com']
12 |
13 | spec.summary = 'Adds OpenCensus support to Marginalia.'
14 | # spec.homepage = "TODO: Put your gem's website or public repo URL here."
15 | # spec.license = "TODO
16 | spec.required_ruby_version = '>= 2.3.0'
17 |
18 | # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19 | # to allow pushing to a single host or delete this section to allow pushing to any host.
20 | if spec.respond_to?(:metadata)
21 | # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
22 |
23 | # spec.metadata["homepage_uri"] = spec.homepage
24 | # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
25 | # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
26 | else
27 | fail 'RubyGems 2.0 or newer is required to protect against ' \
28 | 'public gem pushes.'
29 | end
30 |
31 | # Specify which files should be added to the gem when it is released.
32 | # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
33 | spec.files = Dir.chdir(File.expand_path(__dir__)) do
34 | `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
35 | end
36 | spec.bindir = 'exe'
37 | spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
38 | spec.require_paths = ['lib']
39 |
40 | spec.add_dependency 'actionpack', '>= 5.2.0'
41 | spec.add_dependency 'activerecord', '>= 5.2.0'
42 | spec.add_dependency 'marginalia', '>= 1.8.0', '< 2'
43 | spec.add_dependency 'opencensus', '~> 0.4.0'
44 |
45 | spec.add_development_dependency 'bundler', '~> 2.0'
46 | spec.add_development_dependency 'rake', '~> 12.3'
47 |
48 | # Testing:
49 | spec.add_development_dependency 'capybara', '~> 3.20.2'
50 | spec.add_development_dependency 'combustion', '~> 1.1'
51 | spec.add_development_dependency 'rspec', '~> 3.0'
52 | spec.add_development_dependency 'rspec-rails', '~> 4.0.0.beta2'
53 | spec.add_development_dependency 'wwtd', '~> 1.3.0'
54 | end
55 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/marginalia-opencensus/rubocop.gemfile:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | gem 'rubocop', '~> 0.69.0'
4 | gem 'rubocop-performance', '~> 1.3.0'
5 | gem 'rubocop-rspec', '~> 1.33.0'
6 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/marginalia-opencensus/spec/gemfiles/rails_5_2.gemfile:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | source 'https://rubygems.org'
4 | gemspec path: '../../'
5 |
6 | gem 'rails', '~> 5.2.3'
7 |
8 | # https://github.com/rails/rails/blob/v5.2.2/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb#L12
9 | gem 'sqlite3', '~> 1.3.6'
10 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/marginalia-opencensus/spec/gemfiles/rails_6_0.gemfile:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | source 'https://rubygems.org'
4 | gemspec path: '../../'
5 |
6 | gem 'rails', '~> 6.0.0.rc1'
7 |
8 | # https://github.com/rails/rails/blob/v6.0.0.rc1/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb#L12
9 | gem 'sqlite3', '~> 1.3', '>= 1.3.6'
10 |
11 | gem 'rails-controller-testing'
12 | gem 'rspec-rails', '~> 4.0.0.beta2'
13 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/marginalia-opencensus/spec/gemfiles/rubocop.gemfile:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | source 'https://rubygems.org'
4 |
5 | eval_gemfile '../../rubocop.gemfile'
6 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/marginalia-opencensus/spec/internal/Rakefile:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require File.expand_path('config/application', __dir__)
4 |
5 | Combustion::Application.load_tasks
6 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/marginalia-opencensus/spec/internal/app/controllers/internal_app_controller.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | # frozen_string_literal: true
18 |
19 | class InternalAppController < ActionController::Base
20 | def simple_query
21 | OpenCensus::Trace.in_span 'my-span' do |_span|
22 | ActiveRecord::Base.connection.select_values 'SELECT 1;'
23 | end
24 | head :ok
25 | end
26 | end
27 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/marginalia-opencensus/spec/internal/config/application.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | # frozen_string_literal: true
18 |
19 | require File.expand_path('boot', __dir__)
20 |
21 | require 'action_controller/railtie'
22 | require 'active_record/railtie'
23 |
24 | require 'combustion'
25 | require 'marginalia-opencensus'
26 | require 'marginalia'
27 | require 'opencensus/trace/integrations/rails'
28 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/marginalia-opencensus/spec/internal/config/boot.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | # frozen_string_literal: true
18 |
19 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__)
20 | require 'bundler/setup'
21 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/marginalia-opencensus/spec/internal/config/database.yml:
--------------------------------------------------------------------------------
1 | development:
2 | adapter: sqlite3
3 | database: db/combustion_development.sqlite
4 |
5 | test:
6 | adapter: sqlite3
7 | database: db/combustion_test.sqlite
8 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/marginalia-opencensus/spec/internal/config/environment.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | # frozen_string_literal: true
18 |
19 | require File.expand_path('application', __dir__)
20 | Combustion.initialize! :active_record, :action_controller
21 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/marginalia-opencensus/spec/internal/config/routes.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | # frozen_string_literal: true
18 |
19 | Rails.application.routes.draw do
20 | scope controller: :internal_app do
21 | get 'simple_query', action: :simple_query, as: :internal_app_simple_query
22 | end
23 | end
24 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/marginalia-opencensus/spec/internal/db/.gitignore:
--------------------------------------------------------------------------------
1 | *.sqlite
2 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/marginalia-opencensus/spec/internal/db/schema.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | # frozen_string_literal: true
18 |
19 | ActiveRecord::Schema.define do
20 | # Set up any tables you need to exist for your test suite that don't belong
21 | # in migrations.
22 | end
23 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/marginalia-opencensus/spec/internal/log/.gitignore:
--------------------------------------------------------------------------------
1 | *.log
2 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/marginalia-opencensus/spec/internal/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-telemetry/opentelemetry-sqlcommenter/2f8841add68358069ebf1c0ee560ab3e98a59aa9/ruby/sqlcommenter-ruby/marginalia-opencensus/spec/internal/public/favicon.ico
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/marginalia-opencensus/spec/marginalia/opencensus/integration_spec.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | # frozen_string_literal: true
18 |
19 | RSpec.feature 'Integration tests', type: :feature do
20 | before do
21 | @queries = []
22 | ActiveSupport::Notifications.subscribe 'sql.active_record' do |_name, _start, _finish, _id, payload|
23 | @queries << payload[:sql]
24 | end
25 | end
26 |
27 | after do
28 | ActiveSupport::Notifications.unsubscribe 'sql.active_record'
29 | end
30 |
31 | it 'appends OpenCensus information to the query on request' do
32 | visit internal_app_simple_query_path
33 | expect(@queries[0]).to(
34 | match(%r{
35 | SELECT[ ]1;[ ]/\*
36 | application:Combustion,
37 | controller:internal_app,
38 | action:simple_query,
39 | traceparent:[0-9]{2}-[a-z0-9]{32}-[a-z0-9]{16}-[0-9]{2}
40 | \*/
41 | }x)
42 | )
43 | end
44 | end
45 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/marginalia-opencensus/spec/marginalia/opencensus/marginalia_comment_components_spec.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | # frozen_string_literal: true
18 |
19 | RSpec.describe Marginalia::Comment do # rubocop:disable RSpec/FilePath
20 | describe 'traceparent' do
21 | it 'is set to the correct value inside OpenCensus trace' do
22 | mocked_span_context = OpenStruct.new(
23 | trace_id: '123321',
24 | span_id: '987789',
25 | trace_options: '42',
26 | )
27 | expected_traceparent = '00-123321-987789-42'
28 |
29 | allow(::OpenCensus::Trace).to receive(:span_context).and_return(mocked_span_context)
30 | ::OpenCensus::Trace.start_request_trace do
31 | expect(described_class.traceparent).to eq(expected_traceparent)
32 | end
33 | end
34 |
35 | it 'is set to nil outside of OpenCensus trace' do
36 | expect(described_class.traceparent).to eq(nil)
37 | end
38 | end
39 | end
40 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/marginalia-opencensus/spec/spec_helper.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | # frozen_string_literal: true
18 |
19 | require 'bundler/setup'
20 |
21 | require File.expand_path('internal/config/environment', __dir__)
22 | require 'rspec/rails'
23 | require 'capybara/rspec'
24 |
25 | RSpec.configure do |config|
26 | # Enable flags like --only-failures and --next-failure
27 | config.example_status_persistence_file_path = '.rspec_status'
28 |
29 | # Disable RSpec exposing methods globally on `Module` and `main`
30 | config.disable_monkey_patching!
31 |
32 | config.expect_with :rspec do |c|
33 | c.syntax = :expect
34 | end
35 | end
36 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails/.gitignore:
--------------------------------------------------------------------------------
1 | /.bundle/
2 | /.yardoc
3 | /_yardoc/
4 | /coverage/
5 | /doc/
6 | /pkg/
7 | /spec/reports/
8 | /tmp/
9 |
10 | # rspec failure tracking
11 | .rspec_status
12 | Gemfile.lock
13 | /vendor/
14 | /spec/gemfiles/*.gemfile.lock
15 | /spec/gemfiles/.bundle/
16 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails/.rspec:
--------------------------------------------------------------------------------
1 | --format documentation
2 | --color
3 | --require spec_helper
4 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails/.rubocop.yml:
--------------------------------------------------------------------------------
1 | require:
2 | - rubocop-performance
3 | - rubocop-rspec
4 |
5 | AllCops:
6 | TargetRubyVersion: 2.3
7 | Exclude:
8 | - 'spec/dummy/db/**/*'
9 | - 'vendor/**/*'
10 |
11 | Bundler/OrderedGems:
12 | Enabled: false
13 |
14 | Capybara/FeatureMethods:
15 | EnabledMethods:
16 | - feature
17 |
18 | Layout/MultilineMethodCallIndentation:
19 | EnforcedStyle: indented
20 |
21 | Lint/AmbiguousBlockAssociation:
22 | Enabled: false
23 |
24 | Metrics/AbcSize:
25 | Enabled: false
26 |
27 | Metrics/BlockLength:
28 | Exclude:
29 | - Rakefile
30 | - spec/**/*_spec.rb
31 | - spec/dummy/config/environments/*.rb
32 | - spec/factories.rb
33 |
34 | Metrics/ClassLength:
35 | Max: 125
36 |
37 | Metrics/LineLength:
38 | Max: 120
39 |
40 | Metrics/MethodLength:
41 | Max: 25
42 |
43 | Metrics/ModuleLength:
44 | Exclude:
45 | - spec/**/*_spec.rb
46 |
47 | Metrics/PerceivedComplexity:
48 | Enabled: false
49 |
50 | Naming/MemoizedInstanceVariableName:
51 | Enabled: false
52 |
53 | Naming/FileName:
54 | Exclude:
55 | - lib/marginalia-opencensus.rb
56 |
57 | Naming/PredicateName:
58 | Exclude:
59 | - spec/**/*.rb
60 |
61 | Naming/VariableNumber:
62 | EnforcedStyle: snake_case
63 |
64 | Naming/UncommunicativeMethodParamName:
65 | Enabled: false
66 |
67 | Rails/ApplicationRecord:
68 | Enabled: false
69 |
70 | Rails/CreateTableWithTimestamps:
71 | Enabled: false
72 |
73 | Rails/SkipsModelValidations:
74 | Enabled: false
75 |
76 | RSpec/FilePath:
77 | CustomTransform:
78 | OpenCensus: opencensus
79 |
80 | Style/AndOr:
81 | Enabled: false
82 |
83 | Style/CollectionMethods:
84 | Enabled: true
85 |
86 | Style/Documentation:
87 | Enabled: false
88 |
89 | Style/Lambda:
90 | EnforcedStyle: literal
91 |
92 | Style/StderrPuts:
93 | Enabled: false
94 |
95 | Style/SignalException:
96 | EnforcedStyle: semantic
97 |
98 | Style/TrailingCommaInArguments:
99 | Enabled: false
100 |
101 | Style/TrailingCommaInArrayLiteral:
102 | Enabled: false
103 |
104 | Style/TrailingCommaInHashLiteral:
105 | Enabled: false
106 |
107 | Rails:
108 | Enabled: true
109 |
110 | Rails/Date:
111 | EnforcedStyle: strict
112 |
113 | Rails/FindBy:
114 | Enabled: true
115 | Include:
116 | - app/commands/**/*.rb
117 | - app/models/**/*.rb
118 | - app/view_models/**/*.rb
119 |
120 | RSpec/BeforeAfterAll:
121 | Enabled: false
122 |
123 | RSpec/ContextWording:
124 | Enabled: false
125 |
126 | RSpec/DescribeClass:
127 | Exclude:
128 | - spec/views/**/*.rb
129 |
130 | RSpec/ExampleLength:
131 | Enabled: false
132 |
133 | RSpec/ExpectInHook:
134 | Enabled: false
135 |
136 | RSpec/InstanceVariable:
137 | Enabled: false
138 |
139 | RSpec/LetSetup:
140 | Enabled: false
141 |
142 | RSpec/MessageSpies:
143 | Enabled: false
144 |
145 | RSpec/MultipleExpectations:
146 | Enabled: false
147 |
148 | RSpec/NestedGroups:
149 | Enabled: false
150 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails/.travis.yml:
--------------------------------------------------------------------------------
1 | ---
2 | sudo: false
3 | language: ruby
4 | cache: bundler
5 | bundler_args: --path ../../vendor/bundle --without debug
6 | env:
7 | global:
8 | - TRAVIS=1
9 | before_install: gem install bundler -v 2.0.1
10 | script: bundle exec rspec
11 | matrix:
12 | include:
13 | - name: Rubocop
14 | gemfile: spec/gemfiles/rubocop.gemfile
15 | rvm: 2.6.3
16 | script: bundle exec rubocop
17 | - gemfile: spec/gemfiles/rails_5_2.gemfile
18 | rvm: 2.3.8
19 | - gemfile: spec/gemfiles/rails_6_0.gemfile
20 | rvm: 2.5.5
21 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails/Gemfile:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | source 'https://rubygems.org'
4 |
5 | gem 'rails', '~> 6.0.0.rc1'
6 | # https://github.com/rails/rails/blob/v6.0.0.rc1/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb#L12
7 | gem 'sqlite3', '~> 1.3', '>= 1.3.6'
8 |
9 | gemspec
10 |
11 | eval_gemfile File.expand_path('shared.gemfile', __dir__)
12 |
13 | group :debug do
14 | gem 'byebug'
15 | end
16 |
17 | eval_gemfile File.expand_path('rubocop.gemfile', __dir__)
18 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails/Rakefile:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require 'bundler/gem_tasks'
4 | require 'rspec/core/rake_task'
5 |
6 | APP_RAKEFILE = File.expand_path('spec/internal/Rakefile', __dir__)
7 | load 'rails/tasks/engine.rake'
8 |
9 | RSpec::Core::RakeTask.new(:spec)
10 |
11 | task default: :spec
12 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails/bin/console:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | # frozen_string_literal: true
3 |
4 | require 'bundler/setup'
5 | require 'sqlcommenter_rails'
6 |
7 | # You can add fixtures and/or initialization code here to make experimenting
8 | # with your gem easier. You can also use a different console, if you like.
9 |
10 | # (If you use this, don't forget to add pry to your Gemfile!)
11 | # require "pry"
12 | # Pry.start
13 |
14 | require 'irb'
15 | IRB.start(__FILE__)
16 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails/bin/rails:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | # frozen_string_literal: true
3 |
4 | APP_PATH = File.expand_path('../spec/internal/config/application', __dir__)
5 | require File.expand_path('../spec/internal/config/boot', __dir__)
6 | require 'rails/commands'
7 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails/bin/setup:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | set -euo pipefail
3 | IFS=$'\n\t'
4 | set -vx
5 |
6 | bundle install
7 |
8 | # Do any other automated setup that you need to do here
9 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails/lib/sqlcommenter_rails.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | # frozen_string_literal: true
18 |
19 | require 'marginalia'
20 | require 'marginalia-opencensus'
21 |
22 | require_relative 'sqlcommenter_rails/marginalia_components'
23 | require_relative 'sqlcommenter_rails/version'
24 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails/lib/sqlcommenter_rails/marginalia_components.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | # frozen_string_literal: true
18 |
19 | module Marginalia
20 | module Comment
21 | # @return [String, nil]
22 | def self.framework
23 | "rails_v#{Rails::VERSION::STRING}"
24 | end
25 |
26 | # @return [String, nil]
27 | def self.db_driver
28 | marginalia_adapter&.class&.name
29 | end
30 |
31 | def self.route
32 | marginalia_controller&.request&.fullpath
33 | end
34 | end
35 | end
36 |
37 | Marginalia::Comment.key_value_separator = '='
38 | Marginalia::Comment.quote_values = :single
39 | Marginalia::Comment.components += %i[framework db_driver route]
40 | Marginalia::Comment.components.sort!
41 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails/lib/sqlcommenter_rails/version.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | # frozen_string_literal: true
18 |
19 | module SqlCommenterRails
20 | VERSION = '0.1.1'
21 | end
22 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails/rubocop.gemfile:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | gem 'rubocop', '~> 0.69.0'
4 | gem 'rubocop-performance', '~> 1.3.0'
5 | gem 'rubocop-rspec', '~> 1.33.0'
6 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails/shared.gemfile:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | gem 'marginalia', path: '../marginalia'
4 | gem 'marginalia-opencensus', path: '../marginalia-opencensus'
5 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails/spec/gemfiles/rails_5_2.gemfile:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | source 'https://rubygems.org'
4 | gemspec path: '../../'
5 | eval_gemfile '../../shared.gemfile'
6 |
7 | gem 'rails', '~> 5.2.3'
8 |
9 | # https://github.com/rails/rails/blob/v5.2.2/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb#L12
10 | gem 'sqlite3', '~> 1.3.6'
11 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails/spec/gemfiles/rails_6_0.gemfile:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | source 'https://rubygems.org'
4 | gemspec path: '../../'
5 | eval_gemfile '../../shared.gemfile'
6 |
7 | gem 'rails', '~> 6.0.0.rc1'
8 |
9 | # https://github.com/rails/rails/blob/v6.0.0.rc1/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb#L12
10 | gem 'sqlite3', '~> 1.3', '>= 1.3.6'
11 |
12 | gem 'rails-controller-testing'
13 | gem 'rspec-rails', '~> 4.0.0.beta2'
14 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails/spec/gemfiles/rubocop.gemfile:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | source 'https://rubygems.org'
4 |
5 | eval_gemfile '../../rubocop.gemfile'
6 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails/spec/internal/Rakefile:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require File.expand_path('config/application', __dir__)
4 |
5 | Combustion::Application.load_tasks
6 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails/spec/internal/app/controllers/internal_app_controller.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | # frozen_string_literal: true
18 |
19 | class InternalAppController < ActionController::Base
20 | def simple_query
21 | OpenCensus::Trace.in_span 'my-span' do |_span|
22 | ActiveRecord::Base.connection.select_values 'SELECT 1;'
23 | end
24 | head :ok
25 | end
26 | end
27 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails/spec/internal/config/application.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | # frozen_string_literal: true
18 |
19 | require File.expand_path('boot', __dir__)
20 |
21 | require 'action_controller/railtie'
22 | require 'active_record/railtie'
23 |
24 | require 'combustion'
25 | require 'marginalia-opencensus'
26 | require 'marginalia'
27 | require 'opencensus/trace/integrations/rails'
28 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails/spec/internal/config/boot.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | # frozen_string_literal: true
18 |
19 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__)
20 | require 'bundler/setup'
21 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails/spec/internal/config/database.yml:
--------------------------------------------------------------------------------
1 | development:
2 | adapter: sqlite3
3 | database: db/combustion_development.sqlite
4 |
5 | test:
6 | adapter: sqlite3
7 | database: db/combustion_test.sqlite
8 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails/spec/internal/config/environment.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | # frozen_string_literal: true
18 |
19 | require File.expand_path('application', __dir__)
20 | Combustion.initialize! :active_record, :action_controller
21 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails/spec/internal/config/routes.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | # frozen_string_literal: true
18 |
19 | Rails.application.routes.draw do
20 | scope controller: :internal_app do
21 | get 'simple_query', action: :simple_query, as: :internal_app_simple_query
22 | end
23 | end
24 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails/spec/internal/db/.gitignore:
--------------------------------------------------------------------------------
1 | *.sqlite
2 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails/spec/internal/db/schema.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | # frozen_string_literal: true
18 |
19 | ActiveRecord::Schema.define do
20 | # Set up any tables you need to exist for your test suite that don't belong
21 | # in migrations.
22 | end
23 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails/spec/internal/log/.gitignore:
--------------------------------------------------------------------------------
1 | *.log
2 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails/spec/internal/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-telemetry/opentelemetry-sqlcommenter/2f8841add68358069ebf1c0ee560ab3e98a59aa9/ruby/sqlcommenter-ruby/sqlcommenter_rails/spec/internal/public/favicon.ico
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails/spec/spec_helper.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | # frozen_string_literal: true
18 |
19 | require 'bundler/setup'
20 |
21 | require File.expand_path('internal/config/environment', __dir__)
22 | require 'rspec/rails'
23 | require 'capybara/rspec'
24 |
25 | RSpec.configure do |config|
26 | # Enable flags like --only-failures and --next-failure
27 | config.example_status_persistence_file_path = '.rspec_status'
28 |
29 | # Disable RSpec exposing methods globally on `Module` and `main`
30 | config.disable_monkey_patching!
31 |
32 | config.expect_with :rspec do |c|
33 | c.syntax = :expect
34 | end
35 | end
36 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails/spec/sqlcommenter_rails/integration_spec.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | # frozen_string_literal: true
18 |
19 | RSpec.describe 'Integration tests', type: :feature do
20 | before do
21 | @queries = []
22 | ActiveSupport::Notifications.subscribe 'sql.active_record' do |_name, _start, _finish, _id, payload|
23 | @queries << payload[:sql]
24 | end
25 | end
26 |
27 | after do
28 | ActiveSupport::Notifications.unsubscribe 'sql.active_record'
29 | end
30 |
31 | it 'appends OpenCensus information to the query on request' do
32 | visit internal_app_simple_query_path
33 | puts @queries[0]
34 | expect(@queries[0]).to(
35 | match(%r{
36 | SELECT[ ]1;[ ]/\*
37 | action='simple_query',
38 | application='Combustion',
39 | controller='internal_app',
40 | db_driver='ActiveRecord::ConnectionAdapters::SQLite3Adapter',
41 | framework='rails_v[^']+',
42 | route='/simple_query',
43 | traceparent='[0-9]{2}-[a-z0-9]{32}-[a-z0-9]{16}-[0-9]{2}'
44 | \*/
45 | }x)
46 | )
47 | end
48 | end
49 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails/spec/sqlcommenter_rails/marginalia_comment_components_spec.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | # frozen_string_literal: true
18 |
19 | RSpec.describe Marginalia::Comment do # rubocop:disable RSpec/FilePath
20 | describe 'framework' do
21 | it 'is set to the correct Rails version' do
22 | expect(described_class.framework).to eq("rails_v#{Rails::VERSION::STRING}")
23 | end
24 | end
25 | end
26 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails/sqlcommenter_rails.gemspec:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | lib = File.expand_path('lib', __dir__)
4 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5 | require 'sqlcommenter_rails/version'
6 |
7 | Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
8 | spec.name = 'sqlcommenter_rails'
9 | spec.version = SqlCommenterRails::VERSION
10 | spec.authors = ['OpenTelemetry Authors']
11 | spec.email = ['cncf-opentelemetry-contributors@lists.cncf.io']
12 |
13 | spec.summary = 'sqlcommenter for Ruby on Rails'
14 | # spec.homepage = "TODO: Put your gem's website or public repo URL here."
15 | # spec.license = "TODO
16 | spec.required_ruby_version = '>= 2.3.0'
17 |
18 | # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19 | # to allow pushing to a single host or delete this section to allow pushing to any host.
20 | if spec.respond_to?(:metadata)
21 | # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
22 |
23 | # spec.metadata["homepage_uri"] = spec.homepage
24 | # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
25 | # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
26 | else
27 | fail 'RubyGems 2.0 or newer is required to protect against ' \
28 | 'public gem pushes.'
29 | end
30 |
31 | # Specify which files should be added to the gem when it is released.
32 | # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
33 | spec.files = Dir.chdir(File.expand_path(__dir__)) do
34 | `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
35 | end
36 | spec.bindir = 'exe'
37 | spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
38 | spec.require_paths = ['lib']
39 |
40 | spec.add_dependency 'actionpack', '>= 5.2.0'
41 | spec.add_dependency 'activerecord', '>= 5.2.0'
42 | spec.add_dependency 'marginalia', '>= 1.8.0', '< 2'
43 | spec.add_dependency 'marginalia-opencensus', '~> 0.1.0'
44 |
45 | spec.add_development_dependency 'bundler', '~> 2.0'
46 | spec.add_development_dependency 'rake', '~> 12.3'
47 |
48 | # Testing:
49 | spec.add_development_dependency 'capybara', '~> 3.20.2'
50 | spec.add_development_dependency 'combustion', '~> 1.1'
51 | spec.add_development_dependency 'rspec', '~> 3.0'
52 | spec.add_development_dependency 'rspec-rails', '~> 4.0.0.beta2'
53 | spec.add_development_dependency 'wwtd', '~> 1.3.0'
54 | end
55 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails_demo/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files for more about ignoring files.
2 | #
3 | # If you find yourself ignoring temporary files generated by your text editor
4 | # or operating system, you probably want to add a global ignore instead:
5 | # git config --global core.excludesfile '~/.gitignore_global'
6 |
7 | # Ignore bundler config.
8 | /.bundle
9 |
10 | # Ignore the default SQLite database.
11 | /db/*.sqlite3
12 | /db/*.sqlite3-journal
13 |
14 | # Ignore all logfiles and tempfiles.
15 | /log/*
16 | /tmp/*
17 | !/log/.keep
18 | !/tmp/.keep
19 |
20 | # Ignore uploaded files in development.
21 | /storage/*
22 | !/storage/.keep
23 | .byebug_history
24 |
25 | # Ignore master key for decrypting credentials and more.
26 | /config/master.key
27 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails_demo/.ruby-version:
--------------------------------------------------------------------------------
1 | ruby-2.6.3
2 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails_demo/Gemfile:
--------------------------------------------------------------------------------
1 | source 'https://rubygems.org'
2 | git_source(:github) { |repo| "https://github.com/#{repo}.git" }
3 |
4 | gem 'sqlcommenter_rails', path: '../sqlcommenter_rails'
5 | gem 'marginalia', path: '../marginalia'
6 | gem 'marginalia-opencensus', path: '../marginalia-opencensus'
7 |
8 | gem 'opencensus', '~> 0.4.0'
9 |
10 | # Rails 6.0.0.rc1 --api gems below.
11 |
12 | gem 'activerecord', '~> 6.0.0.rc1'
13 | gem 'actionpack', '~> 6.0.0.rc1'
14 | gem 'railties', '~> 6.0.0.rc1'
15 | gem 'bundler', '>= 2.0.1'
16 |
17 | gem 'sqlite3', '~> 1.4'
18 | gem 'puma', '>= 3.12.4'
19 |
20 | group :development, :test do
21 | # Call 'byebug' anywhere in the code to stop execution and get a debugger console
22 | gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
23 | end
24 |
25 | group :development do
26 | gem 'listen', '>= 3.0.5', '< 3.2'
27 | end
28 |
29 | # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
30 | gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
31 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails_demo/README.md:
--------------------------------------------------------------------------------
1 | # sqlcommenter_rails demo
2 |
3 | This is a demo [Rails API] application to demonstrate [sqlcommenter_rails] integration.
4 |
5 | [Rails API]: https://guides.rubyonrails.org/api_app.html
6 | [sqlcommenter_rails]: https://github.com/open-telemetry/opentelemetry-sqlcommenter/ruby/sqlcommenter-ruby/sqlcommenter_rails
7 |
8 | ## Setup
9 |
10 | Install [Ruby v2.6.3](https://www.ruby-lang.org/en/news/2019/04/17/ruby-2-6-3-released/) if you don't already have it installed.
11 |
12 | This demo requires functionality provided by an [open PR](https://github.com/basecamp/marginalia/pull/89) to [marginalia](https://github.com/basecamp/marginalia). Install the PR by cloning [glebm's fork of marginalia](https://github.com/glebm/marginalia) one directory above this demo. Starting from the root directory of this demo:
13 |
14 | ```bash
15 | git clone https://github.com/glebm/marginalia.git ../marginalia
16 | git -C ../marginalia checkout formatting
17 | ```
18 |
19 | Install dependencies and prepare the database:
20 |
21 | ```bash
22 | bin/setup
23 | ```
24 |
25 | Start the server:
26 |
27 | ```bash
28 | bin/rails s
29 | ```
30 |
31 | Run this command in a separate terminal to monitor SQL queries:
32 |
33 | ```bash
34 | tail -f log/development.log | grep 'Post '
35 | ```
36 |
37 | ## Usage
38 |
39 | The demo app has 2 endpoints: `GET /posts` and `POST /posts`.
40 |
41 | ### GET /posts
42 |
43 | ```bash
44 | curl localhost:3000/posts
45 | ```
46 |
47 |
48 | Post Load (0.1ms) SELECT "posts".* FROM "posts" /*action='index',application='SqlcommenterRailsDemo',controller='posts',db_driver='ActiveRecord::ConnectionAdapters::SQLite3Adapter',framework='rails_v6.0.0.rc1',route='/posts',traceparent='00-828f28f7fb3df3dd07ee6478b2016b2a-a52cad0a8d1425ab-01'*/
49 |
50 |
51 | ### POST /posts
52 |
53 | ```bash
54 | curl -X POST localhost:3000/posts -d 'title=my-post'
55 | ```
56 |
57 |
58 | Post Create (0.2ms) INSERT INTO "posts" ("title", "created_at", "updated_at") VALUES (?, ?, ?) /*action='create',application='SqlcommenterRailsDemo',controller='posts',db_driver='ActiveRecord::ConnectionAdapters::SQLite3Adapter',framework='rails_v6.0.0.rc1',route='/posts',traceparent='00-ff19308b1f17fedc5864e929bed1f44e-6ddace73a9debf63-01'*/ [["title", "my-post"], ["created_at", "2019-06-08 15:47:59.089692"], ["updated_at", "2019-06-08 15:47:59.089692"]]
59 |
60 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails_demo/Rakefile:
--------------------------------------------------------------------------------
1 | # Add your own tasks in files placed in lib/tasks ending in .rake,
2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3 |
4 | require_relative 'config/application'
5 |
6 | Rails.application.load_tasks
7 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails_demo/app/controllers/application_controller.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | class ApplicationController < ActionController::API
18 | end
19 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails_demo/app/controllers/posts_controller.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | class PostsController < ApplicationController
18 | def index
19 | render json: Post.all
20 | end
21 |
22 | def create
23 | title = params[:title].to_s.strip
24 | head :bad_request if title.empty?
25 | render json: Post.create!(title: title)
26 | end
27 | end
28 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails_demo/app/models/application_record.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | class ApplicationRecord < ActiveRecord::Base
18 | self.abstract_class = true
19 | end
20 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails_demo/app/models/post.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | class Post < ApplicationRecord
18 | end
19 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails_demo/bin/rails:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | begin
3 | load File.expand_path('../spring', __FILE__)
4 | rescue LoadError => e
5 | raise unless e.message.include?('spring')
6 | end
7 | APP_PATH = File.expand_path('../config/application', __dir__)
8 | require_relative '../config/boot'
9 | require 'rails/commands'
10 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails_demo/bin/rake:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | begin
3 | load File.expand_path('../spring', __FILE__)
4 | rescue LoadError => e
5 | raise unless e.message.include?('spring')
6 | end
7 | require_relative '../config/boot'
8 | require 'rake'
9 | Rake.application.run
10 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails_demo/bin/setup:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | require 'fileutils'
3 |
4 | # path to your application root.
5 | APP_ROOT = File.expand_path('..', __dir__)
6 |
7 | def system!(*args)
8 | system(*args) || abort("\n== Command #{args} failed ==")
9 | end
10 |
11 | FileUtils.chdir APP_ROOT do
12 | # This script is a way to setup or update your development environment automatically.
13 | # This script is idempotent, so that you can run it at anytime and get an expectable outcome.
14 | # Add necessary setup steps to this file.
15 |
16 | puts '== Installing dependencies =='
17 | system! 'gem install bundler --conservative'
18 | system('bundle check') || system!('bundle install')
19 |
20 | # puts "\n== Copying sample files =="
21 | # unless File.exist?('config/database.yml')
22 | # FileUtils.cp 'config/database.yml.sample', 'config/database.yml'
23 | # end
24 |
25 | puts "\n== Preparing database =="
26 | system! 'bin/rails db:prepare'
27 |
28 | puts "\n== Removing old logs and tempfiles =="
29 | system! 'bin/rails log:clear tmp:clear'
30 |
31 | puts "\n== Restarting application server =="
32 | system! 'bin/rails restart'
33 | end
34 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails_demo/bin/spring:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 |
3 | # This file loads spring without using Bundler, in order to be fast.
4 | # It gets overwritten when you run the `spring binstub` command.
5 |
6 | unless defined?(Spring)
7 | require 'rubygems'
8 | require 'bundler'
9 |
10 | lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read)
11 | spring = lockfile.specs.detect { |spec| spec.name == "spring" }
12 | if spring
13 | Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
14 | gem 'spring', spring.version
15 | require 'spring/binstub'
16 | end
17 | end
18 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails_demo/config.ru:
--------------------------------------------------------------------------------
1 | # This file is used by Rack-based servers to start the application.
2 |
3 | require_relative 'config/environment'
4 |
5 | run Rails.application
6 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails_demo/config/application.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | require_relative 'boot'
18 |
19 | require "rails"
20 | # Pick the frameworks you want:
21 | require "active_record/railtie"
22 | require "action_controller/railtie"
23 | # require "sprockets/railtie"
24 | require "rails/test_unit/railtie"
25 |
26 | require "opencensus/trace/integrations/rails"
27 |
28 | # Require the gems listed in Gemfile, including any gems
29 | # you've limited to :test, :development, or :production.
30 | Bundler.require(*Rails.groups)
31 |
32 | module SqlcommenterRailsDemo
33 | class Application < Rails::Application
34 | # Initialize configuration defaults for originally generated Rails version.
35 | config.load_defaults 6.0
36 |
37 | # Settings in config/environments/* take precedence over those specified here.
38 | # Application configuration can go into files in config/initializers
39 | # -- all .rb files in that directory are automatically loaded after loading
40 | # the framework and any gems in your application.
41 |
42 | # Only loads a smaller set of middleware suitable for API only apps.
43 | # Middleware like session, flash, cookies can be added back manually.
44 | # Skip views, helpers and assets when generating a new resource.
45 | config.api_only = true
46 | end
47 | end
48 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails_demo/config/boot.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
18 |
19 | require 'bundler/setup' # Set up gems listed in the Gemfile.
20 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails_demo/config/cable.yml:
--------------------------------------------------------------------------------
1 | development:
2 | adapter: async
3 |
4 | test:
5 | adapter: test
6 |
7 | production:
8 | adapter: redis
9 | url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
10 | channel_prefix: sqlcommenter_rails_demo_production
11 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails_demo/config/credentials.yml.enc:
--------------------------------------------------------------------------------
1 | f8sfeWbtW62TbCT3bDpQ7hQbr6XQsiCgPn6JpuZQ26o7xOlncxrMvAmwYZ2oRbhycl91K9flOpoj9BHVWlkSBThDr0dWfwvTGG3mO5u0QIqzd2JxbRhKGylg/DWknhNLxdA3BEFx213gJ6iJeTiHuqrp63Hy/icHIgbRxPyhjTsUM8Urk61RLDg17nH98qmt4QT2aYHayt9xrrHnDatk/IkPuU6+1PFdsJ7ukFCA3HeIjU/L7ePvjYfvrYNwOUMUq8MFbmfXRlE16Nnjra0oj6GTqdwUvEl9QBcxuIB9KP3cyz8WFOa2/ZUA30NB1UQIoptl4II9+SKKNOVDYI2QKhF2Mc6FL+nUg9h1RVC391BDU1owVxvwH6Jw/LxEAZPPNtRFiy+Bs/ffx/0qx23kkytAhnD0q0V0/1HU--kFHF7iLCoQ1rs71C--GBpjCTogoNu8o9RHWelEYw==
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails_demo/config/database.yml:
--------------------------------------------------------------------------------
1 | # SQLite version 3.x
2 | # gem install sqlite3
3 | #
4 | # Ensure the SQLite 3 gem is defined in your Gemfile
5 | # gem 'sqlite3'
6 | #
7 | default: &default
8 | adapter: sqlite3
9 | pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
10 | timeout: 5000
11 |
12 | development:
13 | <<: *default
14 | database: db/development.sqlite3
15 |
16 | # Warning: The database defined as "test" will be erased and
17 | # re-generated from your development database when you run "rake".
18 | # Do not set this db to the same as development or production.
19 | test:
20 | <<: *default
21 | database: db/test.sqlite3
22 |
23 | production:
24 | <<: *default
25 | database: db/production.sqlite3
26 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails_demo/config/environment.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | # Load the Rails application.
18 | require_relative 'application'
19 |
20 | # Initialize the Rails application.
21 | Rails.application.initialize!
22 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails_demo/config/environments/development.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | Rails.application.configure do
18 | # Settings specified here will take precedence over those in config/application.rb.
19 |
20 | # In the development environment your application's code is reloaded on
21 | # every request. This slows down response time but is perfect for development
22 | # since you don't have to restart the web server when you make code changes.
23 | config.cache_classes = false
24 |
25 | # Do not eager load code on boot.
26 | config.eager_load = false
27 |
28 | # Show full error reports.
29 | config.consider_all_requests_local = true
30 |
31 | # Enable/disable caching. By default caching is disabled.
32 | # Run rails dev:cache to toggle caching.
33 | if Rails.root.join('tmp', 'caching-dev.txt').exist?
34 | config.cache_store = :memory_store
35 | config.public_file_server.headers = {
36 | 'Cache-Control' => "public, max-age=#{2.days.to_i}"
37 | }
38 | else
39 | config.action_controller.perform_caching = false
40 |
41 | config.cache_store = :null_store
42 | end
43 |
44 | # Store uploaded files on the local file system (see config/storage.yml for options).
45 | # config.active_storage.service = :local
46 |
47 | # Don't care if the mailer can't send.
48 | # config.action_mailer.raise_delivery_errors = false
49 |
50 | # config.action_mailer.perform_caching = false
51 |
52 | # Print deprecation notices to the Rails logger.
53 | config.active_support.deprecation = :log
54 |
55 | # Raise an error on page load if there are pending migrations.
56 | config.active_record.migration_error = :page_load
57 |
58 | # Highlight code that triggered database queries in logs.
59 | config.active_record.verbose_query_logs = true
60 |
61 |
62 | # Raises error for missing translations.
63 | # config.action_view.raise_on_missing_translations = true
64 |
65 | # Use an evented file watcher to asynchronously detect changes in source code,
66 | # routes, locales, etc. This feature depends on the listen gem.
67 | config.file_watcher = ActiveSupport::EventedFileUpdateChecker
68 | end
69 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails_demo/config/environments/test.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | # The test environment is used exclusively to run your application's
18 | # test suite. You never need to work with it otherwise. Remember that
19 | # your test database is "scratch space" for the test suite and is wiped
20 | # and recreated between test runs. Don't rely on the data there!
21 |
22 | Rails.application.configure do
23 | # Settings specified here will take precedence over those in config/application.rb.
24 |
25 | config.cache_classes = false
26 |
27 | # Do not eager load code on boot. This avoids loading your whole application
28 | # just for the purpose of running a single test. If you are using a tool that
29 | # preloads Rails for running tests, you may have to set it to true.
30 | config.eager_load = false
31 |
32 | # Configure public file server for tests with Cache-Control for performance.
33 | config.public_file_server.enabled = true
34 | config.public_file_server.headers = {
35 | 'Cache-Control' => "public, max-age=#{1.hour.to_i}"
36 | }
37 |
38 | # Show full error reports and disable caching.
39 | config.consider_all_requests_local = true
40 | config.action_controller.perform_caching = false
41 | config.cache_store = :null_store
42 |
43 | # Raise exceptions instead of rendering exception templates.
44 | config.action_dispatch.show_exceptions = false
45 |
46 | # Disable request forgery protection in test environment.
47 | config.action_controller.allow_forgery_protection = false
48 |
49 | # Store uploaded files on the local file system in a temporary directory.
50 | # config.active_storage.service = :test
51 |
52 | # config.action_mailer.perform_caching = false
53 |
54 | # Tell Action Mailer not to deliver emails to the real world.
55 | # The :test delivery method accumulates sent emails in the
56 | # ActionMailer::Base.deliveries array.
57 | # config.action_mailer.delivery_method = :test
58 |
59 | # Print deprecation notices to the stderr.
60 | config.active_support.deprecation = :stderr
61 |
62 | # Raises error for missing translations.
63 | # config.action_view.raise_on_missing_translations = true
64 | end
65 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails_demo/config/puma.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | # Puma can serve each request in a thread from an internal thread pool.
18 | # The `threads` method setting takes two numbers: a minimum and maximum.
19 | # Any libraries that use thread pools should be configured to match
20 | # the maximum value specified for Puma. Default is set to 5 threads for minimum
21 | # and maximum; this matches the default thread size of Active Record.
22 | #
23 | max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
24 | min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
25 | threads min_threads_count, max_threads_count
26 |
27 | # Specifies the `port` that Puma will listen on to receive requests; default is 3000.
28 | #
29 | port ENV.fetch("PORT") { 3000 }
30 |
31 | # Specifies the `environment` that Puma will run in.
32 | #
33 | environment ENV.fetch("RAILS_ENV") { "development" }
34 |
35 | # Specifies the number of `workers` to boot in clustered mode.
36 | # Workers are forked web server processes. If using threads and workers together
37 | # the concurrency of the application would be max `threads` * `workers`.
38 | # Workers do not work on JRuby or Windows (both of which do not support
39 | # processes).
40 | #
41 | # workers ENV.fetch("WEB_CONCURRENCY") { 2 }
42 |
43 | # Use the `preload_app!` method when specifying a `workers` number.
44 | # This directive tells Puma to first boot the application and load code
45 | # before forking the application. This takes advantage of Copy On Write
46 | # process behavior so workers use less memory.
47 | #
48 | # preload_app!
49 |
50 | # Allow puma to be restarted by `rails restart` command.
51 | plugin :tmp_restart
52 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails_demo/config/routes.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | Rails.application.routes.draw do
18 | resources :posts, only: %i[index create]
19 | # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
20 | end
21 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails_demo/config/spring.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | Spring.watch(
18 | ".ruby-version",
19 | ".rbenv-vars",
20 | "tmp/restart.txt",
21 | "tmp/caching-dev.txt"
22 | )
23 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails_demo/config/storage.yml:
--------------------------------------------------------------------------------
1 | test:
2 | service: Disk
3 | root: <%= Rails.root.join("tmp/storage") %>
4 |
5 | local:
6 | service: Disk
7 | root: <%= Rails.root.join("storage") %>
8 |
9 | # Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
10 | # amazon:
11 | # service: S3
12 | # access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
13 | # secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
14 | # region: us-east-1
15 | # bucket: your_own_bucket
16 |
17 | # Remember not to checkin your GCS keyfile to a repository
18 | # google:
19 | # service: GCS
20 | # project: your_project
21 | # credentials: <%= Rails.root.join("path/to/gcs.keyfile") %>
22 | # bucket: your_own_bucket
23 |
24 | # Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key)
25 | # microsoft:
26 | # service: AzureStorage
27 | # storage_account_name: your_account_name
28 | # storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %>
29 | # container: your_container_name
30 |
31 | # mirror:
32 | # service: Mirror
33 | # primary: local
34 | # mirrors: [ amazon, google, microsoft ]
35 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails_demo/db/migrate/20190608153219_create_posts.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | class CreatePosts < ActiveRecord::Migration[6.0]
18 | def change
19 | create_table :posts do |t|
20 | t.text :title
21 |
22 | t.timestamps
23 | end
24 | end
25 | end
26 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails_demo/db/schema.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | # This file is auto-generated from the current state of the database. Instead
18 | # of editing this file, please use the migrations feature of Active Record to
19 | # incrementally modify your database, and then regenerate this schema definition.
20 | #
21 | # This file is the source Rails uses to define your schema when running `rails
22 | # db:schema:load`. When creating a new database, `rails db:schema:load` tends to
23 | # be faster and is potentially less error prone than running all of your
24 | # migrations from scratch. Old migrations may fail to apply correctly if those
25 | # migrations use external dependencies or application code.
26 | #
27 | # It's strongly recommended that you check this file into your version control system.
28 |
29 | ActiveRecord::Schema.define(version: 2019_06_08_153219) do
30 |
31 | create_table "posts", force: :cascade do |t|
32 | t.text "title"
33 | t.datetime "created_at", precision: 6, null: false
34 | t.datetime "updated_at", precision: 6, null: false
35 | end
36 |
37 | end
38 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails_demo/log/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-telemetry/opentelemetry-sqlcommenter/2f8841add68358069ebf1c0ee560ab3e98a59aa9/ruby/sqlcommenter-ruby/sqlcommenter_rails_demo/log/.keep
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails_demo/test/controllers/posts_controller_test.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | require 'test_helper'
18 |
19 | class PostsControllerTest < ActionDispatch::IntegrationTest
20 | test "GET index" do
21 | get posts_url
22 | assert_response :success
23 | assert_match /"One"/, response.body
24 | assert_match /"Two"/, response.body
25 | end
26 |
27 | test "POST create" do
28 | post posts_url, params: {title: 'My Post'}
29 | assert_response :success
30 | assert_match /"My Post"/, response.body
31 | end
32 | end
33 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails_demo/test/fixtures/posts.yml:
--------------------------------------------------------------------------------
1 | # Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2 |
3 | one:
4 | title: One
5 |
6 | two:
7 | title: Two
8 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails_demo/test/test_helper.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby
2 | #
3 | # Copyright The OpenTelemetry Authors
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | ENV['RAILS_ENV'] ||= 'test'
18 | require_relative '../config/environment'
19 | require 'rails/test_help'
20 |
21 | class ActiveSupport::TestCase
22 | # Run tests in parallel with specified workers
23 | parallelize(workers: :number_of_processors)
24 |
25 | # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
26 | fixtures :all
27 |
28 | # Add more helper methods to be used by all tests here...
29 | end
30 |
--------------------------------------------------------------------------------
/ruby/sqlcommenter-ruby/sqlcommenter_rails_demo/tmp/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-telemetry/opentelemetry-sqlcommenter/2f8841add68358069ebf1c0ee560ab3e98a59aa9/ruby/sqlcommenter-ruby/sqlcommenter_rails_demo/tmp/.keep
--------------------------------------------------------------------------------